我有一个可在多个服务器上使用的SOAP Web服务,因此具有多个端点。我想避免添加具有不同名称的多个服务引用(C#SOAP端口客户端),以便与此服务进行通信,因为API完全相同。
有没有办法在运行时配置端点URI?
答案 0 :(得分:23)
我使用以下效果很好:
ServiceReference1.wsSoapClient ws= new ServiceReference1.wsSoapClient();
ws.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://xxx/myservice.asmx");
答案 1 :(得分: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);
}