简体   繁体   中英

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?

I use the following which works great:

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

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("PagingService@rl.gov"));

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM