Using a C# Service Reference SOAP Client with different Endpoint URIs

beberlei picture beberlei · Aug 9, 2010 · Viewed 43.9k times · Source

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?

Answer

Jimbo picture Jimbo · Jan 20, 2012

I use the following which works great:

        ServiceReference1.wsSoapClient ws= new ServiceReference1.wsSoapClient();
        ws.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://xxx/myservice.asmx");