Reputation: 1695
I created a RESTful WCF web service and the returned content whether XML, JSON, plain text etc. is automatically being wrapped inside a root XML element:
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">.....content.....</string>
Is this standard behavior? Also is there a setting that can turn this off?
Upvotes: 3
Views: 1476
Reputation: 87218
If you're returning a string in XML format, you can't simply return the string "as is", otherwise you may not have valid XML, so yes, that's the standard behavior (the default response is how the DataContractSerializer would serialize the result).
If you don't want wrapped data, you can move to the raw mode, by returning a Stream (more details at http://blogs.msdn.com/b/carlosfigueira/archive/2008/04/17/wcf-raw-programming-model-web.aspx). If you still want to return a CLR type, but you want to control the serialization format, you can either create a data contract to use, or create a type decorated with the XML serialization attributes (XmlElementAttribute
, XmlTextAttribute
, XmlAttributeAttribute
, etc) and mark the operation (or the contract itself) with the XmlSerializerFormatAttribute
.
Upvotes: 5