在运行时设置WCF端点地址?

时间:2010-04-23 00:08:42

标签: c# wcf configuration

如果我有以下内容:

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

MyServiceClient client = new MyServiceClient(binding, endpoint); 

如何设置端点bindingConfiguration?如果它有助于我的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>

但是我想让用户在运行客户端之前配置它。

由于

2 个答案:

答案 0 :(得分:3)

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

binding = new WSHttpBinding("WSHttpBinding_IManagementService");

答案 1 :(得分:0)

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

<system.serviceModel>

  {...}

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

  {...}

</system.serviceModel>

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