自定义 WCF DataContractSerializer [英] Custom WCF DataContractSerializer

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

问题描述

是否可以用我自己的序列化程序替换 Windows Communication Foundation 中的 dataContractSerializer.如果可能,我该如何实现?

Is it possible to replace dataContractSerializer in Windows Communication Foundation with my own serializer. If it is possible, how can I achieve this?

推荐答案

是的,您可以提供自己的序列化程序实现.默认情况下,WCF 将使用 DataContractSerializer.要提供您自己的序列化程序,您必须编写自己的 IOOperationBehavior,它会找出并删除当前应用的 DataContractSerializerOperationBehavior 来自 OperationDescription::Behaviors 集合,然后应用 DataContractSerializerOperationBehavior 的自定义实例.然后 DataContractSerializerOperationBehavior 负责构建一个 XmlObjectSerializer 实现在它的 CreateSerializer 工厂方法.有关如何执行此操作的一些代码示例,查看 Dan Rigsby 撰写的这篇文章.

Yes, you can provide your own serializer implementation. By default WCF will use the DataContractSerializer. To provide your own serializer you must write your own IOperationBehavior which seeks out and removes the currently applied DataContractSerializerOperationBehavior from the OperationDescription::Behaviors collection and then applies a custom instance of an DataContractSerializerOperationBehavior. The DataContractSerializerOperationBehavior is then responsible for constructing an XmlObjectSerializer implementation in it's CreateSerializer factory methods. For some code samples for how to do this, check out this article by Dan Rigsby.

从那里开始,一切都是关于实现您自己的自定义 XmlObjectSerializer,这将允许您将 XML 信息集序列化为您想要的任何表示形式.

From there, it's all about implementing your own custom XmlObjectSerializer which will allow you to serialize the XML infoset to any representation you want.

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

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