2010-04-23 57 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服務配置編輯器中找到它。