views:

88

answers:

1

Hi,

Is there a chance to get a data contract serializer used by operation (DataContractSerializer/NetDataContractSerializer/XmlSerializer etc) in runtime (for instance using operation behaviour). What I want to achieve is to create some diagnostic code that would serialize messages (in message inspector) using currently attached serializer to compare results.

Thanks, Pawel

A: 

Take a look at creating a message inspector on the service side. From there you can grab the message and check its encoder. The encoder will tell you how its serializing. This is not working code, but it would go something like this:IDispatchMessageInspector.AfterReceiveRequest( ref Message request....){ if ( request.MessageEncoder is typeof(BinaryMessageEncoder) //do stuff.....}

Adam Fyles
I'm an idiot... You gave me a hint :) In message inspector I already have access to Message object. As a matter of fact, to create Message object using Message.CreateMessage static method, you have to provide serializer... So basically message has serializer inside :) I will working provide sample code later...
dragonfly