18

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

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

4

2 回答 2

25

我使用以下效果很好:

        ServiceReference1.wsSoapClient ws= new ServiceReference1.wsSoapClient();
        ws.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://xxx/myservice.asmx");
于 2012-01-20T12:52:43.207 回答
5

我也很难找到这个。我最后只是借用了配置绑定并这样做了:

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);
}
于 2010-09-16T12:59:54.117 回答