Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Current, InstanceContext RequestContext on OperationContext?

Tags:

c#

wcf

I'm looking at the System.ServiceModel.OperationContext

http://msdn.microsoft.com/en-us/library/system.servicemodel.operationcontext(v=vs.110).aspx

I'm trying to understand the difference between:

OperationContext.Current
OperationContext.InstanceContext 
OperationContext.RequestContext

In my testing, they seem to be the same. What am I missing?

like image 731
Adrian Avatar asked Jun 26 '14 15:06

Adrian


1 Answers

Well the obvious answer is that they are not exactly the same. At a high level they are three different Types, not inheriting from a common interface. more specifically they have different properties from each other. But from the way you're asking your question it seems you'd also be interested in what each is used for.

In looking at the msdn documentation, I've pulled out some points from the remarks with some of my own thoughts, as to why it has each of the contexts.

Current(OperationContext) : "the operation context is used to access callback channels in duplex services, to store extra state data across portions of the operations, and to access incoming message headers and properties as well as add outgoing message headers and properties."

RequestContext : "the RequestContext object is the link between the request that comes in and the reply that goes out" this object is really focused on giving you access and control over requests and replies in your service.

InstanceContext : no msdn remarks here, but looking at it, it gives you more in-depth control over the state of the communication infrastructure. i.e the communication channels, hosts, and extensions.

Here are the specific MSDN articles I was looking at for each

OperationContext : http://msdn.microsoft.com/en-us/library/system.servicemodel.operationcontext(v=vs.110).aspx

RequestContext : http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.requestcontext(v=vs.110).aspx

InstanceContext : http://msdn.microsoft.com/en-us/library/system.servicemodel.instancecontext(v=vs.110).aspx

like image 80
Mabdullah Avatar answered Oct 29 '22 18:10

Mabdullah