简体   繁体   English

调用Webservice时.NET客户端无法理解SOAP标头

[英]SOAP Header not understood by .NET client when calling Webservice

I've been trying to call a third-party webservice from a .NET client. 我一直试图从.NET客户端调用第三方Web服务。 I have had to set some custom headers for each request in order to adhere to their Authentication requirements. 我必须为每个请求设置一些自定义标头,以便遵守其身份验证要求。

I have used this answer in order for me to get the request header values to appear as so: 我已经使用了这个答案 ,以便我将请求标头值显示为:

<?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>

(I am doing this by setting the a custom <endpoint><headers /></endpoint> section in config) (我这样做是通过在config中设置自定义<endpoint><headers /></endpoint>部分)

I have inspected the request via Fiddler and it is sending the correct header values, and the webservice is returning expected results. 我通过Fiddler检查了请求,它正在发送正确的标头值,并且webservice正在返回预期的结果。

However, the client is throwing the following exception when it receives the result: 但是,客户端在收到结果时抛出以下异常:

System.ServiceModel.ProtocolException : The header 'Security' from the namespace ' http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd ' was not understood by the recipient of this message, causing the message to not be processed. System.ServiceModel.ProtocolException:名称空间“ http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd ”中的标题“安全性”未被理解由此邮件的收件人,导致邮件不被处理。 This error typically indicates that the sender of this message has enabled a communication protocol that the receiver cannot process. 此错误通常表示此消息的发送方已启用接收方无法处理的通信协议。 Please ensure that the configuration of the client's binding is consistent with the service's binding. 请确保客户端绑定的配置与服务的绑定一致。

The relevant part of the repsonse (from Fiddler) is this: 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>

Basically I'm now lost. 基本上我现在迷路了。 I presume I need to perform some sort of message inspection to flag that header as understood, but it does seem quite a lot of heavy lifting just to interpret a result (which I'm already getting from the webservice). 认为我需要执行某种消息检查来标记该标题,但是为了解释结果(我已经从Web服务获得),它确实看起来相当繁重。

Any help is much appreciated. 任何帮助深表感谢。

If you just want to do the authentication , I did used the following code for my c# console application and it worked. 如果您只是想进行身份验证,我确实在我的c#控制台应用程序中使用了以下代码,并且它运行正常。 I used this code in the config file though under <system.serviceModel> -> <client> -> <endpoint> 我在配置文件中使用了此代码,但在<system.serviceModel> - > <client> - > <endpoint>

<headers>
  <wsse:Security mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" >
     <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <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>
</headers>

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

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