Monday, February 13, 2012

Calling WCF/Web Service Without Adding Service Reference

Sometimes we need to calling service without adding service reference.
Below is the code snippet.

Let Assume that your service name is ConfigurationServices and it has method getCustomerDetails.

we retrieve User Details based on UserId using getCustomerDetails method.  

var factory = new ChannelFactory<ConfigurationServices>(new BasicHttpBinding(), 
           new EndpointAddress("http://localhost/HirenWebServices/ConfigurationServices"));
var proxy = factory.CreateChannel();
 
var response = proxy.getCustomerDetails(
           new getCustomerDetails() { arg0 = AppConfiguration.Current.Userid });
 
var v = response.@return;
 
 

No comments:

Post a Comment