I wanted to know a standard way of accessing web-services in C# where the webservice reference can be defined programmatically.
I have the following scenario :
- Multiple webservices can be set up programmatically. Hence I cannot use the "Add Webservice Reference" provided by Visual Studio (or so I think correct me if I am wrong).
- the webservices added have the same structure/actions/operations/request/responses but may have belong to different domains feeding different data.
e.g :
webservice 01 : http://abc.example.com/getData
webservice 02 : http://xyz.example.net/getData
- Can I still use a proxy generated from one service and use it for another or would I have to handle raw XML responses?
Edit 01 : I wanted to know if the following snippet of accessing the webservice can be generalized to be used for all webservices
var binding = new BasicHttpBinding();
var address = new EndpointAddress("http://www.abc.com/service.asmx");
var factory = new ChannelFactory<IGeneralProxy>(binding, address);
var obj = factory.CreateChannel();
var responseString = obj.GetData("UserName", "Password");
Assert.IsNotNull(responseString);
Where IGeneralProxy
is an interface for the Client
Please let me know if if any of the above points are not clear.