2012-09-11 120 views
1

我有以下的(減少)的代碼,我想通過一個web.config如何在web.config中爲CustomBinding配置TransportSecurityBindingElement?

var security = new TransportSecurityBindingElement(); 
security.EndpointSupportingTokenParameters.SignedEncrypted.Add(new UserNameSecurityTokenParameters()); 

var binding = new CustomBinding(security); 

是否有可能配置來配置這個自定義使用web配置結合?如果可能的話,我如何配置支持令牌參數的端點?我已經試過以下配置,但它不驗證對DotNetConfig.xsd:

<system.serviceModel> 
    <bindings> 
    <customBinding> 
     <binding name="SomeBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"> 
     <transportSecurity> <!-- Fails validation --> 
      <!-- How do I configure the EndpointSupportingTokenParameters -->    
     </transportSecurity> 
     </binding> 
    </customBinding> 
    </bindings> 
    <client> 
    ... 
    </client> 
</system.serviceModel> 

回答

0

我認爲你只是用customBinding/security,也許UserNameOverTransportauthenticationMode

<system.serviceModel> 
    <bindings> 
     <customBinding> 
     <binding> 
      <security authenticationMode="UserNameOverTransport" /> 
     </binding> 
     </customBinding> 
    </bindings> 
</system.serviceModel> 

做不到這一點,你可以嘗試手動添加令牌issuedTokenParameters

<system.serviceModel> 
    <bindings> 
     <customBinding> 
     <binding> 
      <security authenticationMode="UserNameOverTransport"> 
       <issuedTokenParameters tokenType="http://schemas.microsoft.com/ws/2006/05/identitymodel/tokens/UserName" /> 
      </security> 
     </binding> 
     </customBinding> 
    </bindings> 
</system.serviceModel> 

(tokenType從UserNameSecurityTokenParameters被盜)

說實話,這可能是非常麻煩,只是在代碼中執行它更容易。如果您需要根據環境的不同,請在配置中定義工廠並使用DI來使用它來創建綁定。

相關問題