开发者

WCF CreateMessage from custom body xml

开发者 https://www.devze.com 2022-12-24 01:30 出处:网络
I have the following code: string body = \"<custom xml>\"; XDocument doc = XDocument.Parse(body);

I have the following code:

string body = "<custom xml>";

XDocument doc = XDocument.Parse(body);

MemoryStream stream = new MemoryStream();
XmlWriter writer = XmlWriter.Create(stream);
if (writer != null)
{
  doc.Save(writer);
  writer.Flush();
  writer.Close();
}

stream.Position = 0;
XmlReader rd = XmlReader.Create(stream);

Message output = Message.CreateMessage(msg.Version, msg.Headers.Action, rd);
output.Headers.CopyHeadersFrom(msg);
output.Properties.CopyProperties(msg.Properties);

When I try to开发者_如何学Go use the message I get the following error:

hexadecimal value 0x02, is an invalid character. Line 1, position 2.

Any idea why? And what I can do to fix this?


Try something like this:

string body = "<?xml version='1.0'?><custom></custom>";

First of all, you often need the <?xml version='1.0'?> header, and as Marc G. already mentioned, your <custom xml> is not valid XML; first of all, XML tags cannot contain spaces, and second of all the opened tag is never closed.

0

精彩评论

暂无评论...
验证码 换一张
取 消