开发者

WCF Event Order

I need to hook into an event in a slightly unusual manner in WCF.

I'm passing a model from 开发者_高级运维the client to the server, and I need access to that model:

  1. After the model has been created but
  2. Before the incoming data has actually been deserialized to that model

The reason is I actually have deserialization events that are conditional, and ideally I want that condition itself to be a property on the object; thus, I'd have the pattern:

create object->set property->deserialize the rest of the object based on that property

Is there an event in WCF that I can hook into for this? I've got an attribute set up that hooks into the "IOperationBehavior" and "IParameterInspector" set up, but those don't (as far as I can tell) have an action that hooks in between the creation and deserialization events.

Alternatively, I'd be fine with a way of modifying the data coming in off the wire and explicitly adding that property into the incoming data, provided I could guarantee that it would be the first property deserialized.

Any ideas?

[Edit] Minor note, I'm using JSON as the data transport here, not that that should really have an impact on the final solution.


You could theoretically implement a nested envelope, whereby the actual data passed to your WCF service consists of a class (the envelope) which has the data needed to determine how to deserialize and a byte array which consists of the real data in a serialized format. Then you could manage the deserialization of the byte array manually.

Seems there is probably a better way, but I've done similar things and they work.

EDIT: Perhaps an IDispatchMessageInspector is the right place to hook?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜