【发布时间】:2015-03-28 13:34:22
【问题描述】:
我一直在尝试从 .NET 客户端调用第三方 Web 服务。为了符合他们的身份验证要求,我必须为每个请求设置一些自定义标头。
我使用了this answer 以使请求标头值如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" s:mustUnderstand="0">
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-2">
<wsse:Username>Jimbob</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">P@ssword</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</s:Header>
<s:Body>
...
</s:Body>
</s:Envelope>
(我通过在配置中设置自定义<endpoint><headers /></endpoint> 部分来做到这一点)
我已经通过 Fiddler 检查了请求,它正在发送正确的标头值,并且 Web 服务正在返回预期结果。
但是,客户端在收到结果时抛出以下异常:
System.ServiceModel.ProtocolException:来自命名空间“http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd”的标头“Security”未被此消息的接收者理解,导致消息无法处理。此错误通常表明此消息的发送方启用了接收方无法处理的通信协议。请确保客户端绑定的配置与服务的绑定一致。
repsonse 的相关部分(来自 Fiddler)是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<wsse:Security 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" soap:mustUnderstand="1">
<wsse:UsernameToken wsu:Id="UsernameToken-371676">
<wsse:Username>SOMEUSERTOKEN</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">SOMEUSERTOKEN</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
<soap:Body>
...
<soap:Body>
</soap:Envelope>
基本上我现在迷路了。我假设我需要执行某种消息检查以将该标头标记为已理解,但仅解释结果似乎确实需要大量繁重的工作(我已经从网络服务中获得了)。
非常感谢任何帮助。
【问题讨论】:
-
我认为这是服务供应商的问题,他们错误地返回了
<UserNameToken />属性。
标签: c# web-services wcf soap