2010-05-31 47 views
4

我已經將一個基於wsdl的軸作爲服務引用導入到VS 2008項目中。在WCF代理中實現Ws安全性

我需要能夠傳遞安全細節,例如用戶名/密碼和nonce值來調用基於軸的服務。

我特地到這樣做是爲了WSE,這是我瞭解世界恨(有沒有問題)

我有WCF的經驗非常少,但工作如何物理現在所說的終點,由於SO ,但不知道如何成立的SOAPHeaders如下所示的模式:

<S:Envelope 
    xmlns:S="http://www.w3.org/2001/12/soap-envelope" 
    xmlns:ws="http://schemas.xmlsoap.org/ws/2002/04/secext"> 
    <S:Header> 
     <ws:Security> 
      <ws:UsernameToken> 
       <ws:Username>aarons</ws:Username> 
       <ws:Password>snoraa</ws:Password> 
      </ws:UsernameToken> 
     </wsse:Security> 
     ••• 
    </S:Header> 
    ••• 
</S:Envelope> 

任何幫助非常讚賞

謝謝,馬克

回答

4

爲了調用這些服務,通常使用basicHttpBinding(即沒有WS- *實現的SOAP 1.1)或wsHttpBinding(SOAP 1.2,帶有WS- *實現)。

主要問題將獲得所有的安全參數。我有一個類似的網絡服務(基於Java的),我需要調用 - 這裏是我的設置和代碼:

app./web.config

<system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="SoapWithAuth" useDefaultWebProxy="false"> 
      <security mode="TransportCredentialOnly"> 
       <transport clientCredentialType="Basic" proxyCredentialType="None" realm="" /> 
      </security> 
     </binding> 
     </basicHttpBinding> 
    </bindings> 
    <client> 
    <endpoint name="SoapWithAuth" 
        address="http://yourserver:port/YourService" 
        binding="basicHttpBinding" 
        bindingConfiguration="SoapWithAuth" 
        contract="IYourService" /> 
    </client> 
</system.serviceModel> 

,然後在客戶端的代碼中調用時該服務,你需要這段代碼:

IYourServiceClient client = new IYourServiceClient(); 

client.ClientCredentials.UserName.UserName = "username"; 
client.ClientCredentials.UserName.Password = "top-secret"; 

這有幫助嗎?

+1

當然可以,你知道如何爲我們的安全設置一個隨機數值嗎? – harrisonmeister 2010-05-31 18:59:56

0

WCF客戶端代理不支持密碼摘要選項。唯一的方法是自己構建UsernameToken,然後在發送消息之前將其注入到SOAP頭中。

我有一個類似的問題,描述爲here,這應該足以幫助您解決同樣的問題。

我最終爲UsernameToken使用了舊的WSE3.0庫,而不是自己編碼哈希算法,然後使用自定義行爲來改變SOAP頭。