首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UsernameToken的WCF设置策略

UsernameToken的WCF设置策略
EN

Stack Overflow用户
提问于 2016-04-21 18:39:10
回答 1查看 868关注 0票数 1

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

代码语言:javascript
复制
    <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中的服务引用->配置服务选项,我更新了我的引用。这产生了一个customBinding,取代了我以前的basicHttpBinding

代码语言:javascript
复制
<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中有什么选项可以让它工作呢?

如果我在TransportWithMessageCredential中使用我的TransportWithMessageCredential,我会得到以下错误:

提供的URI无效;预期将使用HTTPS。

我使用SoapUI运行这个程序。除了UserName和帕斯罗德之外,我还必须提供WSS-PasswordType作为PasswordText。如果不提供此参数,我将在SoapUI中得到一个错误

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

我不知道如何在我的basicHttpBinding中提供WSS。

我的basicHttpBinding如下所示

代码语言:javascript
复制
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
                       }
                   };
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-21 21:09:49

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

代码语言:javascript
复制
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;
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36777893

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档