views:

318

answers:

2

I have a SOAP Webservice that is available on multiple servers, thus having multiple endpoints. I want to avoid adding multiple Service References (C# SOAP Port Clients) with different names just to talk to this services, since the API is exactly the same.

Is there a way to configure the Endpoint URI at runtime?

A: 

you can use the Url property on the generated class to change the url at runtime.

MyService objService = new MyService();
objService.Url = ""; //Set dynamically
objService.SomeMethod();
Adeel
Hm my service did not have a Url Property. However i found out it has a endpointConfigurationName and endpointUri constructor paraemter. That lead me to the app.config xml file which allowed to specify and configure this.
beberlei
A: 

I had trouble finding this one also. I finally just borrowed the configuration binding and did this:

private static wsXXXX.IwsXXXXClient wsXXXXClientByServer(string sServer)
{
    // strangely, these two are equivalent
    WSHttpBinding binding = new WSHttpBinding("WSHttpBinding_IwsXXXX");
    // WSHttpBinding binding = new WSHttpBinding(SecurityMode.Message, false);

    EndpointAddress remoteAddress = new EndpointAddress(new Uri(string.Format("http://{0}:8732/wsXXXX/", sServer)), new UpnEndpointIdentity("[email protected]"));

    return new wsXXXX.IwsXXXXClient(binding, remoteAddress);
}
BillJam