0

I am trying to implement a restful service in WCF, but am having issues in that the service is unable to deserialize the xml being passed to it. It is trying to map the root element to the operation contract rather than to the data contract. For example, with the following XML packet,

<MyObject>
  <MyField1>asdf</MyField1>
  <MyField2>1234</MyField2>
  ...
</MyObject>

it's unable to deserialize MyObject as the input message since it expects the operation contract at that level.

I don't want to just use all the fields as parameters for the operation contract since 1) there would be more than 5 parameters, and 2) it does not leave room for extension data.

I have a behavior extension set up to log the incoming request. Should I just wrap the incoming message with a root element in order for it to deserialize properly? Or is there a less hacky way of making this work--without forcing the client to change implementation?

Thanks

4

1 回答 1

1

我的解决方案是将我的运营合同更改为

[OperationContract(Action="*")]
void ProcessMessage(Message message);

并使用反序列化消息

var msg = message.GetBody<MyObject>();

与我现有的 DataContract。

更新:我实际上选择使用 XmlSerializer 进行反序列化,因为它允许调用服务重新排列 xml blob 中字段的顺序。

于 2011-02-17T00:34:58.093 回答