是否有可能在Windows通讯基础与我自己的序列替代的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
。要提供自己的序列化,你必须编写自己的 IOperationBehavior
其目的了,并删除当前应用的 DataContractSerializerOperationBehavior
从 OperationDescription ::行为
集合,然后应用的一个自定义实例 DataContractSerializerOperationBehavior
。该DataContractSerializerOperationBehavior将负责构建一个 XmlObjectSerializer
在IT实施的 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信息集序列化到你想要的任何重新presentation。
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.