Compartilhar via


Using CallContext

This topic is specific to a legacy technology that is retained for backward compatibility with existing applications and is not recommended for new development. Distributed applications should now be developed using the Windows Communication Foundation (WCF).

The call context allows a remoting client and a remote object to share information without explicitly passing the information as a parameter or return value. The CallContext class provides a dictionary that can contain any number of objects that are marked as serializable and implement the ILogicalThreadAffinative interface. Objects are added to the CallContext by calling SetData. Objects are retrieved from the CallContext by calling GetData. Objects can be added to the CallContext at any time during the execution of the application.

NoteNote

The CallContext is scoped by thread. There is a separate CallContext object for each thread running in the application.

For a sample illustrating the use of the CallContext object, see Remoting Example: CallContext.

The CallContext object is passed in a message (IMessage implementation) as the "__CallContext" property when a remote call is made. Message sinks can add and retrieve objects in the "__CallContext" property as it passes through the message sink chain.

Asynchronous processing and CallContext

The BeginInvoke method passes the CallContext to the server. When the EndInvoke method is called, the data contained in the CallContext is copied back onto the thread that called BeginInvoke.

See Also

Concepts

Remoting Example: CallContext

Other Resources

CallContexts and Direct Remoting
Advanced Remoting