从WCF静态响应中删除xml名称空间 [英] Remove xml namespaces from WCF restful response

查看:67
本文介绍了从WCF静态响应中删除xml名称空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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名称空间引用(在ASMX版本中不存在),用于XML Schema和实例.我在网络上看到了各种各样的论点,这些论点不应该删除,我不赞成返回纯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静态响应中删除xml名称空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆