【问题标题】:Remove Action Node mustUnderstand from WCF soap request using IClientMessageInspector使用 IClientMessageInspector 从 WCF 肥皂请求中删除操作节点 mustUnderstand
【发布时间】:2016-08-12 04:30:45
【问题描述】:

我正在使用我无权访问且无法修改的 WSDL 访问 WCF 服务。对于其中一个请求,远程服务正在死亡,因为我们正在发送:

<Action s:mustUnderstand="1"....>

经过广泛搜索,我找不到解决问题的简单方法。所以, 在典型的消息中:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none" />
  </s:Header>
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <retrieveBooking xmlns="http://services.rccl.com/Interfaces/RetrieveBooking">
      <OTA_ReadRQ TransactionActionCode="RetrievePrice" SequenceNmbr="1" Version="1" xmlns="http://www.opentravel.org/OTA/2003/05/alpha">

我想我可以删除这个节点作为消息检查器的一部分:

internal class MyMessageInspector : IClientMessageInspector
{
   public object BeforeSendRequest(ref Message aRequest, IClientChannel aChannel)
   {
        //Get rid of mustUnderstand Action node
        foreach (MessageHeaderInfo headerInfo in aRequest.Headers.UnderstoodHeaders)
        {
            aRequest.Headers.UnderstoodHeaders.Remove(headerInfo);
        }

        return null;
   }
} 

但是,即使在我删除所有元素后 aRequest.Headers.UnderstoodHeaders 为空,我仍然看到在 XML 中发出 Action 节点。

  1. 我必须做些什么才能完成这项工作?
  2. 如何到达 消息内容,以便我可以检查第一个节点的名称 在这种情况下,主体标签 retrieveBooking? (我只需要做 这是针对特定消息的,而不是所有消息)

【问题讨论】:

    标签: c# web-services wcf soap


    【解决方案1】:

    最终答案非常简单。

    public object BeforeSendRequest(ref Message aRequest, IClientChannel aChannel)
    {
       //For the CabinDetail message the API provider has requested that we REMOVE the XML action node from the header as it causes their end to fail
       //<s:Header>
       //<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none" />
       //</s:Header>
       if (aRequest.ToString().Contains("CabinDetail"))
       {
           int headerIndexOfAction = aRequest.Headers.FindHeader("Action", "http://schemas.microsoft.com/ws/2005/05/addressing/none");
           aRequest.Headers.RemoveAt(headerIndexOfAction);
       }
    
       return null;
    }
    

    【讨论】:

    • 对不起,我正在处理同样的问题,但我使用的是 IClientMessageFormatter。当我返回没有标头的新消息时,我得到一个异常:没有 SOAPAction 标头!'。你是怎么解决这个问题的?
    【解决方案2】:

    替换

    [System.ServiceModel.OperationContractAttribute(Action ="", ReplyAction="*")]
    

    [System.ServiceModel.OperationContractAttribute(Action ="*", ReplyAction="*")]
    

    【讨论】:

      猜你喜欢
      • 2011-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多