2016-04-21 86 views
1

设置策略,我收到了更新的WSDL为服务我消费具有以下政策加入WCF - 为用户名令牌

<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取代我以前的基本HttpBinding

<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 basicBinding,我得到以下错误:

The provided URI is Invalid; HTTPS is expected

我跑这使用了SoapUI。除了UserName和Passwrod,我必须提供WSS-PasswordType作为PasswordText。如果没有提供这个参数,我得到一个错误了SoapUI

Error on verifying message against security policy Error code:1000

我不知道如何在我的basicHttpBinding的供应WSS-PasswordType。

我basicHttpBinding的是如下

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 
         } 
        }; 
    } 

回答

1

我能够通过改变我结合自定义绑定来解决这个

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; 
    }