簡體   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