1

我正在尝试在 .NET 中创建 Web 服务客户端。我添加了服务引用,Visual Studio 创建了以下绑定:

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

但我得到q0:FailedAuthentication.

我发现只有当我设置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>
4

2 回答 2

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;
        }
于 2013-08-27T07:01:43.810 回答
0

如果没有 SSL,请使用ClearUsernameBinding 。如果有 SSL,请使用:

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

在任何一种情况下,打开服务器上的 wcf 日志和跟踪,以查看您的消息与soapUI 有何不同以及内部服务器异常是什么。

于 2013-08-26T12:55:05.560 回答