2013-01-14 83 views
2

根據http://msdn.microsoft.com/en-us/library/system.servicemodel.wshttpbinding.security.aspx,.NET Framework 4.5的WSHttpBinding類有一個公共Security屬性System.ServiceModel.WSHttpSecurity類型。如何到達WSHttpBinding的安全屬性?

問題是WSHttpBinding缺少該屬性。如果我檢查該類型與調試器的一個對象,它沒有顯示出這樣的性質:

Debug inspector showing no Security property

此外,智能感知顯示沒有Security屬性:

enter image description here

重要:注意我正在設置Security屬性使用對象初始值設定項!視覺Stuido對此很好!?

Correct way communicate WSSE Usernametoken for SOAP webservice中,@Chris Marisic顯示了他修改此對象的位置。

此應用程序正在爲.NET Framework 4.5進行編譯。

什麼給?

+2

什麼類型是'service.Endpoint.Binding'?它可能是超類型的'WSHttpBinding',所以它只顯示其實際定義類型的相關屬性。 **編輯**:[ClientBase.Endpoint.Binding](http://msdn.microsoft.com/en-us/library/system.servicemodel.description.serviceendpoint.binding.aspx)鍵入['Binding']( http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.binding.aspx),因此您只能看到與該類型相關的屬性。 – mellamokb

+1

按照http://msdn.microsoft.com/en-us/library/system.servicemodel.endpoint.binding.aspx – msmucker0527

回答

2

問題是ClientBase.EndpointBinding屬性的類型是System.ServiceModel.Channels.Binding,它是一個通用抽象類,它是所有綁定類型的父類型。所以你正在看到這種類型的智能感知。

在分配實例之前,您需要設置實際的WSHttpBinding實例的屬性,就像您現在正在使用對象初始化語法一樣。另一種方法是先將它分配給局部變量:

var binding = new WSHttpBinding(SecurityMode....); 
binding.Security = new WSHttpSecurity(); 
// etc. 
service.Endpoint.Binding = binding; 
+0

這是一個泛型的'System.ServiceModel.Channels.Binding'就是這樣。謝謝! –