【问题标题】:How to update client endpoint binding in code如何在代码中更新客户端端点绑定
【发布时间】:2015-04-01 13:17:03
【问题描述】:

我有一个关于在代码中修改客户端端点绑定的问题。 我添加了一个 Web 服务引用并为它创建了一个客户端端点绑定。 在 web.config 中,我将绑定设置为基本 https,我想将其更改为 ex。 http,我在 web.config 中指定的名称为“basicHttpBinding”。当我创建 Web 服务引用的实例时,无法使用地址和绑定,因为没有采用此类参数的构造函数。

  <endpoint address="http://localhost/LocalService/SendRequest.asmx"
    binding="basicHttpsBinding" bindingConfiguration="basicHttpsBinding"
    contract="LocalService.SendRequest" name="LocalServiceClient" />

任何如何解决此问题的建议将不胜感激。

干杯!

【问题讨论】:

    标签: c# web-services binding web-config


    【解决方案1】:
    var binding = new System.ServiceModel.BasicHttpBinding() { Name = "LocalServiceClient", Namespace = "LocalService.SendRequest" };
    var endPoint = new System.ServiceModel.EndpointAddress("http://localhost/LocalService/SendRequest.asmx");
    var client = new ServiceClient(binding, endPoint);
    

    【讨论】:

      【解决方案2】:

      如果我理解正确,这就是您要查找的内容:

      var x = new ServiceClient();
      x.Endpoint.Binding = new BasicHttpBinding("optional configuration name");
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多