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="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">
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)
{
aRequest.Headers.UnderstoodHeaders.Remove(headerInfo);
}
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.
Replace
[System.ServiceModel.OperationContractAttribute(Action ="", ReplyAction="*")]
By
[System.ServiceModel.OperationContractAttribute(Action ="*", ReplyAction="*")]
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
//<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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With