2013-08-26 20 views
1

我想在.NET中創建一個Web服務客戶端。我添加服務引用和Visual Studio中創建以下綁定:用明文密碼正確綁定Web服務的配置

<bindings> 
    <basicHttpBinding> 
     <binding name="sample" /> 
    </basicHttpBinding> 
</bindings> 

但我正在逐漸q0:FailedAuthentication.

我發現我越來越引起了SoapUI只有當我設置WSS_TYPEPasswordText

如何在.NET/WCF中設置綁定配置以獲取相同的請求?

下面是了SoapUI請求:

<soapenv:Envelope xmlns:rnl="sample" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soapenv:Header> 
    <wsse:Security soapenv:mustUnderstand="1" 
        xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" 
        xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> 
     <wsse:UsernameToken wsu:Id="UsernameToken-3"> 
     <wsse:Username>username</wsse:Username> 
     <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</wsse:Password> 
     <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">XXXX</wsse:Nonce> 
     <wsu:Created>date</wsu:Created> 
     </wsse:UsernameToken> 
    </wsse:Security> 
    </soapenv:Header> 
    <soapenv:Body> 
    <rnl:GetLastUpdate/> 
    </soapenv:Body> 
</soapenv:Envelope> 

回答

0

使用ClearUsernameBinding的情況下,沒有SSL。如果SSL使用這樣的:

 <basicHttpBinding> 
      <binding name="NewBinding0"> 
       <security mode="TransportWithMessageCredential" /> 
      </binding> 
     </basicHttpBinding> 

,並在WCF日誌這兩種情況下轉彎,跟蹤在服務器上看到您的郵件的soapUI的區別,什麼是內部服務器例外。

0

我找到了答案有幫助: http://benpowell.org/supporting-the-ws-i-basic-profile-password-digest-in-a-wcf-client-proxy/

我需要在BeforeSendRequest

public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel) 
     { 
      UsernameToken token = new UsernameToken(this.Username, this.Password, PasswordOption.SendPlainText); 
      XmlElement securityToken = token.GetXml(new XmlDocument()); 
      MessageHeader securityHeader = MessageHeader.CreateHeader("Security", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", securityToken, false); 
      request.Headers.Add(securityHeader); 
      return null; 
     } 
添加頁眉