从 WCF RESTful 响应中删除 xml 命名空间 [英] Remove xml namespaces from WCF restful response
问题描述
我正在使用 WCF 向调用者返回一个普通的旧 XML (POX) 文档.我正在使用 XML Serializer 格式化程序将对象转换为 XML.
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.
在返回的文档中,我有一些针对 XML Schema 和实例的无关 xml 命名空间引用(在 ASMX 版本中不存在).我在网上看到了各种不应该删除这些的论点,我不赞成返回纯 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.
从 WCF 中返回的 XML 文档中删除这些 xmlns 引用的最简单方法是什么?
What is the simplest way of removing these xmlns references from a returned XML document in WCF?
签名看起来像:
public ResponseInfo Process(string input) {
}
推荐答案
您可以通过将 DataContract 属性的 Namespace 参数设置为空字符串来移除 XML 命名空间,如下所示:
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...
这篇关于从 WCF RESTful 响应中删除 xml 命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!