【发布时间】:2010-08-09 11:42:51
【问题描述】:
我有一个可在多个服务器上使用的 SOAP Web 服务,因此具有多个端点。我想避免添加多个具有不同名称的服务引用(C# SOAP 端口客户端)只是为了与这些服务通信,因为 API 完全相同。
有没有办法在运行时配置端点 URI?
【问题讨论】:
标签: c# soap webservice-client
我有一个可在多个服务器上使用的 SOAP Web 服务,因此具有多个端点。我想避免添加多个具有不同名称的服务引用(C# SOAP 端口客户端)只是为了与这些服务通信,因为 API 完全相同。
有没有办法在运行时配置端点 URI?
【问题讨论】:
标签: c# soap webservice-client
我使用以下效果很好:
ServiceReference1.wsSoapClient ws= new ServiceReference1.wsSoapClient();
ws.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://xxx/myservice.asmx");
【讨论】:
wsSoapClient() 的类实例并在每次我想调用 WebMethod 或 (B) 时使用它 使用using 语句按需实例化并尽快释放?
我也很难找到这个。我终于只是借用了配置绑定并这样做了:
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);
}
【讨论】: