Can you intercept WCF message object creation? (Server side)
If I've got a WCF service that has an exposed method such as:
DoSomething(My开发者_StackOverflow社区Message msg)
Can I intercept the creation of the parameter to the method call or change how it is instantiated?
Edit (for context): I know this is a code smell, so this question is more out of curiosity than anything, but imagine we wanted to use Unity to perform constructor injection on the message on server once the message is received. That's why I want to intercept the message creation - to use Unity to instantiate it.
This web page here has a huge long list of WCF extensibility samples.
If understand your question correctly, you want to be able to handle the invokation of a message on the service class - check out this sample here: Operation Formatter and Selector and the IDispatchOperationSelector interface
You can implement a parameter inspector to inspect parameters prior to sending the message to the service.
The key to implementing a parameter inspector is to implement the IParameterInspector interface. This interface contains two methods: BeforeCall and AfterCall. The signature for these methods follows:
void AfterCall(string operationName, object[] outputs, object returnValue, object
correlationState);
object BeforeCall(string operationName, object[] inputs);
In both cases, the parameters sent to the method are presented to these methods as an array of objects. However, their position in the pipeline depends on whether the inspector is inserted on the client side or the service side. For more info, please see below link:
How to: Inspect or Modify Parameters
In addition to the extensibility points mentioned by marc_s, you might also consider the IOperationInvoker
extensibility point. Depending on exactly what you are trying to do with your parameter, that may fit the bill better or more easily.
精彩评论