Chris W
Chris W

Reputation: 3324

SOAP Header removed during web service call

I'm testing calling a SOAP based service from a .net client app and am running in to some strange problems with the SOAP header seeming to disappear.

A brief explanation of the setup:

I've used a WSDL supplied by the webservice provider to create my proxy objects. In my code a declare an instance of the service client that I want to call. Build up the payload that the method requires and then call the method.

I've defined my own inspector which writes the request message out to a text file in the BeforeSendRequest function so I can examine what is being sent.

My output file includes a SOAP Header specifying the SOAP Action to be called:

<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">urn:actionName</Action>
  </s:Header>
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

However when I examine the request in Fiddler I see:

POST http://itk1:4848/syncsoap HTTP/1.1
Content-Type: text/xml; charset=utf-8
VsDebuggerCausalityData: uIDPo3+FD6fhly5OnM0GeeaNhJ8AAAAAqHE+abP1+EWcEPeRvh8Oj4EFi5tL0elHlKdqfGJg1AIACQAA
SOAPAction: "urn:actionName"
Host: itk1:4848
Content-Length: 9651
Expect: 100-continue
Connection: Keep-Alive

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body

My action seems to have been removed from the SOAP envelope and has become a basic header so when the service I'm calling gets the request it can't find the action in the expected place.

As a test I've tried to instead create a basic request using WebRequest.Create() and post the output file that I retrieved earlier from my message inspector. When this hits Fiddler is shows that the SOAP Header and Action have been retained in in the SOAP envelope.

I presume this is WCF being helpful and amending my request for me? How can I get it to stop screwing around with my message and send it as it was originally constructed?

Upvotes: 1

Views: 2261

Answers (2)

Chris W
Chris W

Reputation: 3324

I've resolved the issue by manually writing my own headers using the message inspector.

i.e. in BeforeSendRequest I'm now doing:

request.Headers.Add(MessageHeader.CreateHeader("Action", WSANamespace, _headerInfo.Action))

Which write it out correctly along with a few other SOAP headers that I need.

Strangely, if I write out the request to my debug listeners I see that the envelope now contains 2 Action headers but by the time the request hits Fiddler everything looks ok with a single Action in the envelope - I'm happy to leave the original action converting to a HTTP Header since the service I'm calling requires that anyway.

Upvotes: 1

taher chhabrawala
taher chhabrawala

Reputation: 4130

Try using a IDispatchMessageFormatter for debugging as shown in this link http://blogs.msdn.com/b/carlosfigueira/archive/2011/05/03/wcf-extensibility-message-formatters.aspx

For understanding stages in WCF pipeline refer http://msdn.microsoft.com/en-us/magazine/cc163302.aspx

Upvotes: 0

Related Questions