开发者

WCF custom XML serialization

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

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

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.

Update: My types are immutable and use raedonly properties, so IXmlSerializable won't work for me.


Implement IXmlSerializable on CustomerEntity.


You can try using Raw messages i.e. using Contract types deriving from Message class and writing the messages the way you want by overriding OnWriteBodyContents and other overridable Message class members. Please refer "Inheriting from the Message Class" section gof following MSDN article to know more about overridable members of Message class, http://msdn.microsoft.com/en-us/library/ms734675.aspx

HTH, Amit

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜