繁体   English   中英

无法在 header 中发送带有摘要认证的 soap 请求

[英]Unable to send soap request with digest authentication in the header

我正在尝试通过 SOAP 与第三方应用程序集成。他们希望所有请求都与 header 类似,如下所示:

<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-DD4E97480F1F85448316117490736656">
            <wsse:Username>E_PARTNER</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">wg0ddtB6cbJ7E0Huxzl8xwcGHGA=</wsse:Password>
            <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">VSrk7BdhGeApgR4BdtKl8Q==</wsse:Nonce>
            <wsu:Created>2021-01-27T12:04:33.664Z</wsu:Created>
        </wsse:UsernameToken>
    </wsse:Security>
</soapenv:Header>

其中Password是公式PasswordDigest = Base64(SHA1(nonce + created + password))的结果。

当我通过 SoapUI 进行测试时一切正常,但是当我想从我的 C# 程序发送它时它失败了。 我认为问题出在我的客户端配置上。 这是我的代码:

// IDK what's going on in the following 3 lines
BasicHttpBinding _binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential);
_binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Digest;
_binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;

var client = new PartnersInteraction.partnersPortTypeClient(_binding, new EndpointAddress("https://urlhere.com"));
client.Endpoint.EndpointBehaviors.Add(_soapLoggingBehavior); // logging
client.ClientCredentials.UserName.UserName = UserName; // username that they gave me 
client.ClientCredentials.UserName.Password = Password; // password that they gave me
OperationContext.Current.OutgoingMessageHeaders.Add(GetHeader()); // here in GetHeader() the header adds to the message

return await client.getUPIDAsync(UserName); // the api method call

PartnersInteraction.partnersPortTypeClient是我从 wsdl 生成的客户端。它是System.ServiceModel.ClientBase的子 class。

我在响应中收到的错误:验证消息时遇到安全错误 原因:处理 wsse:Security header 时发现错误

这是我第一次使用 SOAP,这对我来说似乎太混乱了,所以请大家帮我解决这个问题。 也许我应该在_binding中改变一些东西? 或者问题可能出在PartnersInteraction.partnersPortTypeClient中?

经过几天的搜索,我终于找到了解决方案。 帮助改变这个:

BasicHttpBinding _binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential);
_binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Digest;
_binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;

对此:

BasicHttpBinding _binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM