繁体   English   中英

WCF - UsernameToken 的设置策略

[英]WCF - Setting Policy for UsernameToken

我收到了我正在使用的服务的更新 WSDL,其中添加了以下策略

    <wsp:Policy wssutil:Id="UsernameToken">
<ns0:SupportingTokens xmlns:ns0="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200512">
 <wsp:Policy>
 <ns0:UsernameToken ns0:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200512/IncludeToken/AlwaysToRecipient">
 <wsp:Policy>
  <ns0:WssUsernameToken10 /> 
  </wsp:Policy>
  </ns0:UsernameToken>
  </wsp:Policy>
  </ns0:SupportingTokens>
  </wsp:Policy>

我通过右键单击 Visual Studio 中的服务参考 --> 配置服务选项更新了我的参考。 这生成了一个 customBinding 替换了我之前的 basicHttpBinding

<customBinding>
            <binding name="myBindingName">
                <!--    WsdlImporter encountered unrecognized policy assertions in ServiceDescription 'http://ouaf.oracle.com/webservices/cm/CM-CustConnAcctDetailExtract':    -->
                <!--    <wsdl:binding name='CM-CustConnAcctDetailExtractSoapBinding'>    -->
                <!--        <ns0:SupportingTokens xmlns:ns0="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200512">..</ns0:SupportingTokens>    -->
                <textMessageEncoding messageVersion="Soap11" />
                <httpTransport />
            </binding>
        </customBinding>

我只需要使用这个 customBinding 吗? 或者 basicBinding 中是否有任何选项可以使其工作?

如果我将 basicBinding 与 TransportWithMessageCredential 一起使用,则会出现以下错误:

提供的 URI 无效; 需要 HTTPS

我使用 SoapUI 运行它。 除了 UserName 和 Passwrod 之外,我还必须提供WSS-PasswordType作为PasswordText 不提供此参数,我在 SoapUI 中收到错误

根据安全策略验证消息时出错 错误代码:1000

我不确定如何在我的 basicHttpBinding 中提供 WSS-PasswordType。

我的基本HttpBinding如下

protected BasicHttpBinding GetBinding()
    {
        return new BasicHttpBinding()
                   {
                       Name = "BasicHttpBinding",
                       ReceiveTimeout = new TimeSpan(0, 0, 2, 0),
                       SendTimeout = new TimeSpan(0, 0, 2, 0),
                       Security =
                           {
                               Mode = BasicHttpSecurityMode.TransportCredentialOnly,
                               Transport =
                                   {
                                       ClientCredentialType = HttpClientCredentialType.Basic,
                                       ProxyCredentialType = HttpProxyCredentialType.None,
                                       Realm = ""
                                   },
                               Message =
                                   {
                                       ClientCredentialType = BasicHttpMessageCredentialType.UserName,
                                       AlgorithmSuite = SecurityAlgorithmSuite.Default
                                   }
                           },
                       MaxBufferSize = Int32.MaxValue,
                       MaxReceivedMessageSize = Int32.MaxValue,
                       ReaderQuotas = new XmlDictionaryReaderQuotas()
                       {
                           MaxBytesPerRead = 8192
                       }
                   };
    }

我可以通过将绑定更改为自定义绑定来解决此问题

protected CustomBinding GetCustomBinding()
    {
        var customBinding = new CustomBinding() { Name = "CustomBinding" };

        customBinding.Elements.Add(new TextMessageEncodingBindingElement() { MessageVersion = MessageVersion.Soap11 });
        var securityBindingElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
        securityBindingElement.AllowInsecureTransport = true;
        securityBindingElement.EnableUnsecuredResponse = true;
        securityBindingElement.IncludeTimestamp = false;
        customBinding.Elements.Add(securityBindingElement);
        customBinding.Elements.Add(new HttpTransportBindingElement());

        return customBinding;
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM