Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF message:How to remove the SOAP Header element?

I try to delete the whole SOAP header from a WCF message, just only want to leave the envelope body. Anybody can give me an idea how can do that?

Create a WCF message like this:

**string response = "Hello World!";
Message msg = Message.CreateMessage(MessageVersion.Soap11, "*", new TextBodyWriter(response));
msg.Headers.Clear();**

The sending SOAP message will be:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header />
  <s:Body>
    <Binary>Hello World!</Binary>
  </s:Body>
</s:Envelope>

But I don't want to the SOAP header element, which I just only need the envelop body.How to remove the header element from a WCF message?

like image 326
user1483352 Avatar asked Dec 07 '22 13:12

user1483352


1 Answers

Option 1: Use bacicHttpBinding, it will not add content to the header (when not configured for security)

Option 2: Implement a custom mesaage encoder and strip the header there. anywhere before that there is a chance wcf will add the header back. See sample encoder here.

like image 114
Yaron Naveh Avatar answered Jan 12 '23 13:01

Yaron Naveh