Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove xml namespaces from WCF restful response

I am using WCF to return a plain old XML (POX) document to the caller. I am using the XML Serializer formatter to turn the objects into XML.

In the returned document I have some extraneous xml namespace references (that weren't there in the ASMX version) for the XML Schema and instance. I have seen various arguments on the web that these shouldn't be removed which I don't buy into for returning a plain XML document.

What is the simplest way of removing these xmlns references from a returned XML document in WCF?

The signature looks like:

public ResponseInfo Process(string input) {
}
like image 677
Duncan Avatar asked Jan 27 '09 10:01

Duncan


2 Answers

You can remove the XML namespace by setting the Namespace parameter of the DataContract attribute to an empty string, like so:

[DataContract(Namespace = "")]
public class ResponseInfo
{
    // ...
}

I hope this helps...

like image 179
Kevin Babcock Avatar answered Oct 10 '22 03:10

Kevin Babcock


I had the same problem. Adding BodyStyle:=WebMessageBodyStyle.Bare to WebInvoke worked for me. Response is no longer wrapped in a metadata.

like image 45
user565923 Avatar answered Oct 10 '22 03:10

user565923