WCF Event Order

I need to connect to the event in a somewhat unusual way in WCF.

I pass the model from client to server and I need access to this model:

  • After creating the model, but
  • Before the input was actually deserialized for this model

The reason is that I actually have deserialization events that are conditional, and ideally I want this condition to be a property of the object; this way I will have a template:

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

Is there an event in WCF that I can connect to? I have an attribute configured to intercept the settings of "IOperationBehavior" and "IParameterInspector", but they do not (as far as I can tell) actions that intercept the creation and deserialization events.

Alternatively, I will be fine with changing the data coming from the wire, and explicitly adding this property to the incoming data, if I can guarantee that this will be the first property deserialized.

Any ideas?

[Edit] Minor note. I am using JSON as a data transport here, and not something that should really affect the final decision.

+4
source share
1 answer

Theoretically, you could implement a nested envelope whereby the actual data passed to your WCF service consists of a class (envelope) that has the data needed to define deserialization and an array of bytes that consists of real data in a serialized format. Then you can manually control the deserialization of the byte array.

It seems like probably the best way, but I did similar things and they work.

EDIT: Perhaps IDispatchMessageInspector is a suitable place to intercept?

+1
source

Source: https://habr.com/ru/post/1369674/


All Articles