Windows Dev Center

Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

InstanceContext Class

Represents the context information for a service instance.

Namespace:  System.ServiceModel
Assemblies:   System.ServiceModel.Duplex (in System.ServiceModel.Duplex.dll)
  System.ServiceModel (in System.ServiceModel.dll)

public sealed class InstanceContext : CommunicationObject, 
	IExtensibleObject<InstanceContext>

The InstanceContext type exposes the following members.

  NameDescription
Public methodInstanceContext(Object)Initializes a new instance of the InstanceContext class for a specified object that implements the service instance.
Public methodInstanceContext(ServiceHostBase)Initializes a new instance of the InstanceContext class for a service hosted by a specified host.
Public methodInstanceContext(ServiceHostBase, Object)Initializes a new instance of the InstanceContext class for a specified object that implements the service instance and is hosted by a specified host.
Top

  NameDescription
Public propertyExtensionsGets the extension collection, if any, associated with the service instance.
Public propertyHostGets the host for the service instance.
Public propertyIncomingChannelsGets the sessionful channels that are incoming to the service instance.
Public propertyManualFlowControlLimitGets or sets a limit on the number of messages that can be processed by the instance context.
Public propertyOutgoingChannelsGets the sessionful channels that are outgoing from the service instance.
Public propertyStateGets a value that indicates the current state of the communication object. (Inherited from CommunicationObject.)
Public propertySynchronizationContextGets or sets the context used for thread synchronization with the current instance context.
Top

  NameDescription
Public methodAbortCauses a communication object to transition immediately from its current state into the closing state. (Inherited from CommunicationObject.)
Public methodBeginClose(AsyncCallback, Object)Begins an asynchronous operation to close a communication object. (Inherited from CommunicationObject.)
Public methodBeginClose(TimeSpan, AsyncCallback, Object)Begins an asynchronous operation to close a communication object with a specified timeout. (Inherited from CommunicationObject.)
Public methodBeginOpen(AsyncCallback, Object)Begins an asynchronous operation to open a communication object. (Inherited from CommunicationObject.)
Public methodBeginOpen(TimeSpan, AsyncCallback, Object)Begins an asynchronous operation to open a communication object within a specified interval of time. (Inherited from CommunicationObject.)
Public methodClose()Causes a communication object to transition from its current state into the closed state. (Inherited from CommunicationObject.)
Public methodClose(TimeSpan)Causes a communication object to transition from its current state into the closed state within a specified interval of time. (Inherited from CommunicationObject.)
Public methodEndCloseCompletes an asynchronous operation to close a communication object. (Inherited from CommunicationObject.)
Public methodEndOpenCompletes an asynchronous operation to open a communication object. (Inherited from CommunicationObject.)
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetServiceInstance()Returns the instance of the service for the instance context.
Public methodGetServiceInstance(Message)Returns the instance of the service for the instance context in response to an incoming message.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodIncrementManualFlowControlLimitIncreases the number of messages that can be processed by the service instance.
Public methodOpen()Causes a communication object to transition from the created state into the opened state. (Inherited from CommunicationObject.)
Public methodOpen(TimeSpan)Causes a communication object to transition from the created state into the opened state within a specified interval of time. (Inherited from CommunicationObject.)
Public methodReleaseServiceInstanceReleases the service instance.
Protected methodThrowIfDisposedThrows an exception if the communication object is disposed. (Inherited from CommunicationObject.)
Protected methodThrowIfDisposedOrImmutableThrows an exception if the communication object the State property is not set to the Created state. (Inherited from CommunicationObject.)
Protected methodThrowIfDisposedOrNotOpenThrows an exception if the communication object is not in the Opened state. (Inherited from CommunicationObject.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public eventClosedOccurs when a communication object transitions into the closed state. (Inherited from CommunicationObject.)
Public eventClosingOccurs when a communication object transitions into the closing state. (Inherited from CommunicationObject.)
Public eventFaultedOccurs when a communication object transitions into the faulted state. (Inherited from CommunicationObject.)
Public eventOpenedOccurs when a communication object transitions into the opened state. (Inherited from CommunicationObject.)
Public eventOpeningOccurs when a communication object transitions into the opening state. (Inherited from CommunicationObject.)
Top

The following code illustrates how to obtain instance context information from a service:

string info = "";

OperationContext operationContext = OperationContext.Current;
InstanceContext instanceContext = operationContext.InstanceContext;

info += "    " + "State: " + instanceContext.State.ToString() + "\n";
info += "    " + "ManualFlowControlLimit: " + instanceContext.ManualFlowControlLimit.ToString() + "\n";
info += "    " + "HashCode: " + instanceContext.GetHashCode().ToString() + "\n";

return info;

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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:
© 2015 Microsoft