TheEdge TheEdge - 2 months ago 62x
C# Question

Remove Action Node mustUnderstand from WCF soap request using IClientMessageInspector

I am hitting a WCF service using a WSDL I don't have access to and cannot modify. For one of the requests the remote service is dying because we are sending the:

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

Having searched extensively I cannot find a simple solution to my problem. So,
in a typical message:

<s:Envelope xmlns:s="">
<Action s:mustUnderstand="1" xmlns="" />
<s:Body xmlns:xsi="" xmlns:xsd="">
<retrieveBooking xmlns="">
<OTA_ReadRQ TransactionActionCode="RetrievePrice" SequenceNmbr="1" Version="1" xmlns="">

I figured I could remove this node as part of message inspector:

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)

return null;

however even though the aRequest.Headers.UnderstoodHeaders is empty after I remove all the elements, I am still seeing the Action node being emitted in the XML.

  1. What do I have to do to make this work?

  2. How do I get at the
    message contents so that I can inspect the name of the first node of
    the body tag retrieveBooking in this case? (I only need to do
    this for a specific message, not all of them)


And the answer ends up being very simple in the end.

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
   //<Action s:mustUnderstand="1" xmlns="" />
   if (aRequest.ToString().Contains("CabinDetail"))
       int headerIndexOfAction = aRequest.Headers.FindHeader("Action", "");

   return null;