Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
484 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...