Caling webservice from code file


This code - snippet shows how you can call the webservice from the code file of a web application. When we add reference to a webservice it generates a proxy file and the CustomerService.ClientConfig file which specifies the configuration needed to access the web service. but here we are going to see how we can use our own binding, webservice url to connect to the web service .

This code - snippet shows how you can call the webservice from the code file of a web application. When we add reference to a webservice it generates a proxy file and the CustomerService.ClientConfig file which specifies the configuration needed to access the web service. but here we are going to see how we can use our own binding, webservice url to connect to the web service .
Assuming that proxy is a variable which refers to our webservice.



CustomerServiceClient proxy = new CustomerServiceClient(new BasicHttpBinding(), new EndpointAddress("http://services.myApp.com/CustomerService.svc"));

proxy.GetCountofUsersCompleted+= new EventHandler(proxy_GetCountofUsersCompleted);
proxy.GetCountofUsersCompletedAsync(1);

void proxy_GetCountofUsersCompleted(object sender, CountUsersCompletedEventArgs e)
{
if (e.Error != null)
{
userCountResult.Text = "Error getting the number of users.";
}
else
{
userCountResult.Text = "Number of users is : " + e.Result;
}
}


Article by Vaishali Jain
Miss. Jain Microsoft Certified Technology Specialist in .Net(Windows and Web Based application development)

Follow Vaishali Jain or read 127 articles authored by Vaishali Jain

Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: