使用具有不同端点URI的C#服务引用SOAP客户端
我有一个可以在多个服务器上使用的SOAP Web服务,因此有多个端点。我希望避免添加多个名称不同的服务引用(C#SOAP端口客户端)只是为了与这些服务通信,因为API完全相同使用具有不同端点URI的C#服务引用SOAP客户端,c#,soap,webservice-client,C#,Soap,Webservice Client,我有一个可以在多个服务器上使用的SOAP Web服务,因此有多个端点。我希望避免添加多个名称不同的服务引用(C#SOAP端口客户端)只是为了与这些服务通信,因为API完全相同 有没有办法在运行时配置端点URI?我也很难找到这个。最后,我借用了配置绑定并执行了以下操作: private static wsXXXX.IwsXXXXClient wsXXXXClientByServer(string sServer) { // strangely, these two are equivale
有没有办法在运行时配置端点URI?我也很难找到这个。最后,我借用了配置绑定并执行了以下操作:
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);
}
我使用了以下非常有效的方法:
ServiceReference1.wsSoapClient ws= new ServiceReference1.wsSoapClient();
ws.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://xxx/myservice.asmx");
当我尝试使用不同的端点时,会出现以下错误:“无法识别的消息版本”。你知道为什么吗?还有一个问题,我应该(A)创建
wsSoapClient()
的类实例,并在每次调用WebMethod时使用它,还是(B)使用using
语句按需实例化并尽快释放它?