繁体   English   中英

使用具有不同端点URI的C#服务引用SOAP客户端

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

我有一个SOAP Web服务,可在多个服务器上使用,因此具有多个端点。 我想避免添加具有不同名称的多个服务引用(C#SOAP端口客户端),以便与此服务进行通信,因为API完全相同。

有没有办法在运行时配置端点URI?

我使用以下功能很好:

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

我也很难找到这个。 我终于借用了配置绑定并做了这个:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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