Consume Web Service in Windows Forms application using C# in ASP.Net

zoom
 
on Dec 20, 2016 01:59 AM
7267 Views

windows form code

public void button1_Click(object sender, EventArgs e)
{
    localhost.Service1 h = new localhost.Service1();
    h.Seat(int.Parse(textBox6.Text), radioButton1.Checked, radioButton2.Checked);
    //Recive the information
    MessageBox.Show(textBox5.Text);

} web service code
[WebMethod]
public string Seat(int a, bool E, bool S)
{
    if (E == true && S == false)
    {
        return "Seat Is On C or D Row Line";
    }
    else if (S == true && E == false)
    {
        return "Seat Is On A Row Line";
    }
    else
    {
        if (a > 20)
        {
            return "Seat Is On C or D Row Line";
        }
        else if (a > 13 && a <= 20)
        {
            return "Seat Is On B Row Line";
        }
        else
        {
            return "Seat Is On A Row Line";
        }
    }
}

I'm not able to push the values from the form to web service

any ideas ???

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Dec 22, 2016 08:06 AM
on Oct 30, 2017 06:13 AM

Hi zoom,

Here i have created sample.

Service1.asmx

public class Service1 : System.Web.Services.WebService
{
    [WebMethod]
    public string Seat(int A, bool E, bool S)
    {
        if (E == true && S == false)
        {
            return "Seat Is On C or D Row Line";
        }
        else if (S == true && E == false)
        {
            return "Seat Is On A Row Line";
        }
        else
        {
            if (A > 20)
            {
                return "Seat Is On C or D Row Line";
            }
            else if (A > 13 && A <= 20)
            {
                return "Seat Is On B Row Line";
            }
            else
            {
                return "Seat Is On A Row Line";
            }
        }
    }
}

In Windows form button click event.

private void button1_Click(object sender, EventArgs e)
{
    Service1.Service1SoapClient h = new Service1.Service1SoapClient();
    int A;
    A = int.Parse(Age.Text);
    bool E = false;
    bool S = false;
    MessageBox.Show(h.Seat(A, E, S));
}

Screenshot