我正在使用Message.CreateMessage创建一个Message并将其发送到 WCF 服务端点,但我创建的每条消息都以它开头<?xml version="1.0" encoding="utf-16"?>,导致服务拒绝我的消息Operation is not supported。SOAP 1.1 标准指出,这The Envelope is the top element of the XML document representing the message.可能就是服务拒绝我的消息的原因。不同MessageVersion的 s 不会更改生成的 XML,并且构造函数确实接受 aBodyWriter但 XML 正文不会导致我的问题,它是根元素。
有没有一种方法可以在没有 XML 根元素的情况下生成一个Messagewith ?Message.CreateMessage
编码
internal static Message CreateGetMessage(string id)
{
const string Get = "http://schemas.xmlsoap.org/ws/2004/09/transfer/Get";
const string Rm = "http://schemas.microsoft.com/2006/11/ResourceManagement";
/* unnecessary code removed to create simplest example */
var message = Message.CreateMessage(MessageVersion.Default, Get);
if (message.Headers.FindHeader("ResourceReferenceProperty", Rm) <= 0)
{
message.Headers.Add(MessageHeader.CreateHeader("ResourceReferenceProperty", Rm, id));
}
return message;
}
生成的 SOAP 信封
<?xml version="1.0" encoding="utf-16"?>
<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Header>
<a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2004/09/transfer/Get</a:Action>
<ResourceReferenceProperty xmlns="http://schemas.microsoft.com/2006/11/ResourceManagement">8f2a4ecc-e3dc-1a4c-5a28-4a4a7a8e6644</ResourceReferenceProperty>
</s:Header>
<s:Body />
</s:Envelope>
所需的 SOAP 信封
<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Header>
<a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2004/09/transfer/Get</a:Action>
<ResourceReferenceProperty xmlns="http://schemas.microsoft.com/2006/11/ResourceManagement">8f2a4ecc-e3dc-1a4c-5a28-4a4a7a8e6644</ResourceReferenceProperty>
</s:Header>
<s:Body />
</s:Envelope>
调试
