OperationContextScope Class
TOC
Collapse the table of content
Expand the table of content

OperationContextScope Class

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Creates a block within which an OperationContext object is in scope.

System::Object
  System.ServiceModel::OperationContextScope

Namespace:  System.ServiceModel
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

No code example is currently available or this language may not be supported.

The OperationContextScope type exposes the following members.

  NameDescription
Public methodOperationContextScope(IContextChannel)Initializes a new instance of the OperationContextScope class that uses the specified IContextChannel to create a new OperationContext for the scope.
Public methodOperationContextScope(OperationContext)Initializes a new instance of the OperationContextScope class to create a scope for the specified OperationContext object.
Top

  NameDescription
Public methodDisposeRestores the original OperationContext to the active context and recycles the OperationContextScope object.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

Use the OperationContextScope class to create a scope for a specific OperationContext object or a scope for a new OperationContext object using a specified IContextChannel object. An OperationContextScope can be used in a Windows Communication Foundation (WCF) service as well as in a Windows Phone client application.

After the OperationContextScope object has established the current operation context, you can use the OperationContext to:

  • Access and modify incoming and outgoing message headers and other properties.

  • Access the runtime, including dispatchers, the host, channel, and extensions.

  • Access other types of contexts, such as security, instance, and request contexts.

  • Access the channel associated with the OperationContext object or (if the channel implements System.ServiceModel.Channels::ISession) the associated channel's session identifier.

When an OperationContextScope is created, the current OperationContext is stored and the new OperationContext becomes the one returned by the Current property. When the OperationContextScope is disposed of, the original OperationContext is restored.

Capabilities

If you use this API in your app, you must specify the following capabilities in the app manifest. Otherwise, your app might not work correctly or it might exit unexpectedly.

ID_CAP_NETWORKING

Windows Phone 8, Windows Phone OS 7.1

For more info, see App capabilities and hardware requirements for Windows Phone 8.

The following example shows how to use the OperationContextScope to create a new context in a client application to add a custom header to the outgoing message.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Show:
© 2017 Microsoft