Help me in understanding differences between these two. as per to me, Operation ContextScope can be used irrespective of .NET application you are using like WCF, Console, Web, etc, anywhere this can be used if you are calling any other service like WCF or Java based service [ it this will not work in case of ASMX service] to add headers into outgoing message.
If so then why we need MessageInspectors at any client side to add headers? OperationContextScope is much simpler than MessageInspectors. anybody shed some light to understand the correct usage of these two?
IClientMessageInspector
on the client side andIDispatchMessageInspector
, on the server side are good at inspecting the body of messages, potentially modifying the message before sending, or modifying what is received.Here is a sample :
Write a behavior to easily apply the inspector to a client :
Use the behavior :
Same thing could be done on the server side with IDispatcherMessageInspector.
The behavior could be put with C#, XML (app.config/web.config) or declaratively on the service implementation :
OperationContextScope are useful for handling headers (adding, removing).
Programming WCF Services, Appendix B, from Juval Löwy explains pretty well OperationContextScope. Juval's Framework, ServiceModelEx helps using
OperationContextScopes
with theGenericContext<T>
classSee Juval's Company site for download : http://www.idesign.net/Downloads
Regards