beberlei
beberlei

Reputation: 4337

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

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?

Upvotes: 18

Views: 46297

Answers (2)

Jimbo
Jimbo

Reputation: 22964

I use the following which works great:

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

Upvotes: 26

BillJam
BillJam

Reputation: 221

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);
}

Upvotes: 5

Related Questions