2010-04-23 90 views
2

如果我有以下几点:在运行时设置WCF端点地址?

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> 

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

感谢

回答

3

很简单修复!对不起,问一个愚蠢的问题!

binding = new WSHttpBinding("WSHttpBinding_IManagementService"); 
0

要设置行政约束力,你需要绑定区段添加到您的app.config文件:

<system.serviceModel> 

    {...} 

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

    {...} 

</system.serviceModel> 

如果你不觉得舒适与手动编辑,你可以使用WCF服务配置编辑器,您可以在Visual Studio菜单工具> WCF服务配置编辑器中找到它。