我尝试从 WCF 消息中删除整个 SOAP header ,只想保留信封正文。任何人都可以告诉我如何做到这一点?
像这样创建一个 WCF 消息:
**string response = "Hello World!";
Message msg = Message.CreateMessage(MessageVersion.Soap11, "*", new TextBodyWriter(response));
msg.Headers.Clear();**
发送的 SOAP 消息将是:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header />
<s:Body>
<Binary>Hello World!</Binary>
</s:Body>
</s:Envelope>
但我不需要 SOAP header 元素,我只需要信封主体。如何从 WCF 消息中删除 header 元素?
最佳答案
选项 1:使用 bacicHttpBinding,它不会向 header 添加内容(当未配置安全时)
选项 2:实现自定义消息编码器并去除那里的 header 。在此之前的任何地方,wcf 都有可能将 header 添加回去。参见 sample encoder here .
关于c# - WCF 消息 :How to remove the SOAP Header element?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11211924/