tags:

views:

67

answers:

2

I'm trying to create a Message using only a set of parameters provided by the user and a MessageDescription I resolved by extracting the input message from an OperationDescription object in WCF.

It looks simple, but I can't seem to find information on how to work with settings like Body.WrapperElementName and various message parts that are described in MessageDescription.

Is there any WCF expert that can help me get a feel for this rather complex issue?

A: 

I don't think this functionality is actually exposed directly like that at all.

I haven't tried this, but spent a bit of time with reflector and if you don't mind getting your hands dirty and using a bit of reflection, one option might be to use Activator.CreateInstance() to create a new instance of the System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter class, which implements the the IClientMessageFormatter interface.

Here are the parameters for the constructor:

  • OperationDescription description
  • DataContractFormatAttribute dataContractFormatAttribute
  • DataContractSerializerOperationBehavior serializerFactory

Notice that in any case, you'll need the full OperationDescription object, but looks like you have access to it in any case.

Then, it's just a matter of calling SerializeRequest().

tomasr
Thanks for the pointers. I'm going to try it out. And since I'm using dynamic anyway its already slow as hell, so any more reflection should not matter one bit ;)
W.Meints
Tried it and it sort of works. At the moment it fails because I'm using the wrong parameter types and return types in my DynamicObject derived class, but I'm getting there. I can create a new instance of the type and use that to serialize the parameters of my operation.
W.Meints
A: 

If you can create a [MessageContract] type to represent the message, then you could use the TypedMessageConverter class.

Alternatively you might be able to do this using the DataContractSerializerOperationBehavior. you would need to 'cruft' up some stubs, such as the OperationDescription.

In terms of learning about MessageDescription itself, and the various parameters there, I would recommend creating a [ServiceContract] interface like what you want to see, and then use ContractDescription.GetContract to load the ContractDescription and inspect the MessageDescriptions objects. You can see what WCF uses for defaults, etc.

If you have questions about specific properties I might be able to help.

alexdej