开发者

Create message from a MessageDescription

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.

开发者_StackOverflow社区

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


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().


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜