How to use IDispatchMessageInspector in a WCF Service?

前端 未结 5 1746
面向向阳花
面向向阳花 2020-12-10 13:24

I am trying to use IDispatchMessageInspector in a WCF service implementation to access custom header values.

Something like:

public class MyService :         


        
5条回答
  •  难免孤独
    2020-12-10 14:08

    On the MSDN page that you linked to there is also a description how an inspector can be inserted and also an example of that. To quote:

    Typically, message inspectors are inserted by a service behavior, an endpoint behavior, or a contract behavior. The behavior then adds the message inspector to the DispatchRuntime.MessageInspectors collection.

    Later on you have the following examples:

    • Implementing custom IDispatchMessageInspector
    • Implementing custom IServiceBehavior that adds the inspector to the runtime.
    • Configuration of the behavior via .config file.

    That should be enough to get you started. Otherwise feel free to ask :)

    If you just want to get access to headers from within your service, you could try OperationContext.Current.IncomingMessageHeaders.

提交回复
热议问题