![](/img/trans.png)
[英]Create C# client consumes SOAP service without using built-in 'Add Service Reference…'
[英]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.