WCF Method is returning xml fragment but no xml UTF-8 header

Posted by horls on Stack Overflow See other posts from Stack Overflow or by horls
Published on 2010-06-03T15:12:09Z Indexed on 2010/06/03 15:14 UTC
Read the original article Hit count: 461

Filed under:
|
|

My method does not return the header, just the root element xml.

internal Message CreateReturnMessage(string output, string contentType)
            {
                // create dictionaryReader for the Message
                byte[] resultBytes = Encoding.UTF8.GetBytes(output);
                XmlDictionaryReader xdr = XmlDictionaryReader.CreateTextReader(resultBytes, 0, resultBytes.Length, Encoding.UTF8, XmlDictionaryReaderQuotas.Max, null);

                if (WebOperationContext.Current != null)
                    WebOperationContext.Current.OutgoingResponse.ContentType = contentType;

                // create Message
                return Message.CreateMessage(MessageVersion.None, "", xdr);
            }

However, the output I get is:

<Test>
   <Message>Hello World!</Message> 
</Test>

I would like the output to render as:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Test>
   <Message>Hello World!</Message> 
</Test>

© Stack Overflow or respective owner

Related posts about c#

Related posts about Xml