WCF自定义XML序列化 [英] WCF custom XML serialization

查看:98
本文介绍了WCF自定义XML序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WCF中,如果我有这样的代码并以XML格式返回,则XML是自动生成的。
我是否可以明确指定要用于CustomerEntity序列化的XML?

In WCF, if I have code like this and I'm returning it in XML format, the XML is auto generated. Is it possible for me to expicitly specify which XML will be used for the serialization of the CustomerEntity?

[OperationContract]    
[WebInvoke(Method = "GET"]
CustomerEntity GetCustomer(int customerPk);

我当前正在使用的替代方法是返回XElement,但是这样做的问题是我也无法以这种方式支持JSon。

The alternative that I'm currently using is to return an XElement, but the problem with this is that I can't also support JSon that way.

更新:我的类型是不可变的,并且使用raedonly属性,所以IXmlSerializable对我来说不起作用。

推荐答案

在CustomerEntity上实现IXmlSerializable。

Implement IXmlSerializable on CustomerEntity.

这篇关于WCF自定义XML序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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