1

我想通过 web.config 配置以下(简化的)代码

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>
4

1 回答 1

0

我认为您只是使用customBinding/security,也许与authenticationModeof一起使用UserNameOverTransport

<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 来使用它来创建绑定。

于 2012-09-18T02:21:13.033 回答