【问题标题】:Using a C# Service Reference SOAP Client with different Endpoint URIs使用具有不同端点 URI 的 C# 服务参考 SOAP 客户端
【发布时间】:2010-08-09 11:42:51
【问题描述】:

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

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

【问题讨论】:

    标签: c# soap webservice-client


    【解决方案1】:

    我使用以下效果很好:

            ServiceReference1.wsSoapClient ws= new ServiceReference1.wsSoapClient();
            ws.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://xxx/myservice.asmx");
    

    【讨论】:

    • 当我使用不同的端点尝试此操作时,我收到以下错误:“无法识别的消息版本。”你知道为什么吗?
    • 还有一个问题,我是否应该 (A) 创建一个 wsSoapClient() 的类实例并在每次我想调用 WebMethod 或 (B) 时使用它 使用using 语句按需实例化并尽快释放?
    【解决方案2】:

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

    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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-28
      • 2014-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多