Reputation: 12368
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 :
e.g :
webservice 01 : http://abc.example.com/getData
webservice 02 : http://xyz.example.net/getData
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.
Upvotes: 1
Views: 367
Reputation: 5150
Yes, you can use the same generated proxy for both services as long as the service is the same. I do it all the time.
Here is a snipit of my code. I use WSE 3.0 as the project that I am working on is .net 2.0.
ServiceWse serivce = new ServiceWse();
CookieContainer cookieContainer = new CookieContainer();
serivce.Timeout = 1000 * 60 * CommonFunctions.GetConfigValue<int>(Consts.Common.WebServiceTimeout, 20);
serivce.Url = CommonFunctions.GetConfigValue(Consts.Urls.MyServiceSecuredURL, string.Empty);
serivce.CookieContainer = cookieContainer;
if (CommonFunctions.GetConfigValue(Consts.Security.UseSecuredServices, false))
CommonFunctions.SetWSSecurity(_service.RequestSoapContext);
Upvotes: 1
Reputation: 364
We do something similar. Web service references are created against the Dev version of our services. We also have a setting in the web.config for each web service URI, that we use when instantiating the service; that way, when we deploy to production, all we have to do is change the URI in the web.config, rather than rebuild the project.
var myService= new myService(){Uri = [service uri from web.config]};
Upvotes: 0
Reputation: 260
Check out this previous answer to a similar question:
How to programmatically connect a client to a WCF service?
You can do that for each web service.
Upvotes: 0