简体   繁体   English

WCF - UsernameToken 的设置策略

[英]WCF - Setting Policy for UsernameToken

I received an updated WSDL for a service I'm consuming which has below Policy added我收到了我正在使用的服务的更新 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>

I have updated my reference by right clicking the Service Reference --> Configure Service option inside Visual Studio.我通过右键单击 Visual Studio 中的服务参考 --> 配置服务选项更新了我的参考。 This generated a customBinding replacing my previous basicHttpBinding这生成了一个 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>

Do I need to use this customBinding only?我只需要使用这个 customBinding 吗? Or is there any option in basicBinding that makes it work?或者 basicBinding 中是否有任何选项可以使其工作?

If I use my basicBinding with TransportWithMessageCredential, I get below error:如果我将 basicBinding 与 TransportWithMessageCredential 一起使用,则会出现以下错误:

The provided URI is Invalid;提供的 URI 无效; HTTPS is expected需要 HTTPS

I ran this using SoapUI.我使用 SoapUI 运行它。 In addition to UserName and Passwrod, I had to supply WSS-PasswordType as PasswordText .除了 UserName 和 Passwrod 之外,我还必须提供WSS-PasswordType作为PasswordText Without supplying this parameter, I get an error in SoapUI不提供此参数,我在 SoapUI 中收到错误

Error on verifying message against security policy Error code:1000根据安全策略验证消息时出错 错误代码:1000

I'm not sure how to supply WSS-PasswordType in my basicHttpBinding.我不确定如何在我的 basicHttpBinding 中提供 WSS-PasswordType。

My basicHttpBinding is as below我的基本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
                       }
                   };
    }

I'm able to work this through by changing my binding to Custom Binding我可以通过将绑定更改为自定义绑定来解决此问题

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.

相关问题 WCF:将Nonce添加到UsernameToken - WCF: Adding Nonce to UsernameToken Wcf 服务服务器 - 使用 usernametoken 进行身份验证 - Wcf service server - authentication with usernametoken 通过HTTP具有basicHttpBinding,加密,签名和usernameToken的WCF - WCF with basicHttpBinding, encryption, signing and usernameToken over HTTP C#WCF服务参考-无法创建UserNameToken - C# WCF Service Reference - can not create UserNameToken 将WSE客户端迁移到WCF-如何替换SecurityPolicyAssertion和UsernameToken? - Migrating WSE Client to WCF - how to replace SecurityPolicyAssertion and UsernameToken? 如何在 WCF 客户端服务中实现 WS-security(时间戳、用户名令牌、签名) - How do I implement WS-security in WCF client service (timestamp, usernametoken, signature) 使用 WS-Security UsernameToken PasswordDigest 身份验证方案使用 Axis 2 Web 服务的 WCF 客户端出错 - Error in WCF client consuming Axis 2 web service with WS-Security UsernameToken PasswordDigest authentication scheme WCF - 为oasis-200401-wss-username-token-profile-1.0创建带有时间戳和密码摘要的UserNameToken - WCF - create UserNameToken with timestamp and password digest for oasis-200401-wss-username-token-profile-1.0 如何使WCF客户端符合特定的WS-Security - 签署UsernameToken和SecurityTokenReference - How to make WCF Client conform to specific WS-Security - sign UsernameToken and SecurityTokenReference 设置WCF应用程序的凭据? - Setting credentials for a WCF application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM