【问题标题】:Setting WCF Endpoint address at runtime?在运行时设置 WCF 端点地址?
【发布时间】:2011-02-11 07:54:31
【问题描述】:

如果我有以下情况:

WSHttpBinding binding = new WSHttpBinding(); 
EndpointAddress endpoint = new EndpointAddress(new Uri("http://xxx:pppp/MyService")); 

MyServiceClient client = new MyServiceClient(binding, endpoint); 

如何设置端点绑定配置?如果有帮助,我的 app.config 设置为:

<endpoint address="http://xxx:pppp/Design_Time_Addresses/WcfServiceLibrary/ManagementService/"
          binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IManagementService"
          contract="ServiceReference.IManagementService">
        <identity>
              <dns value="localhost" />
        </identity>
</endpoint>

但是我希望让用户在运行客户端之前进行配置。

谢谢

【问题讨论】:

    标签: c# wcf configuration


    【解决方案1】:

    非常简单的修复!!抱歉问了一个愚蠢的问题!

    binding = new WSHttpBinding("WSHttpBinding_IManagementService");
    

    【讨论】:

      【解决方案2】:

      要以管理方式设置绑定,您需要在 app.config 文件中添加绑定部分:

      <system.serviceModel>
      
        {...}
      
        <bindings>
          <wsHttpBinding>
              <binding name="WSHttpBinding_IManagementService" {other parameters ...} />
          </wsHttpBinding>
        </bindings>
      
        {...}
      
      </system.serviceModel>
      

      如果您对手动编辑不满意,可以使用 WCF 服务配置编辑器,您可以在 Visual Studio 菜单工具>WCF 服务配置编辑器中找到它。

      【讨论】:

        猜你喜欢
        • 2011-07-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-12-18
        • 1970-01-01
        • 2013-09-14
        相关资源
        最近更新 更多