Bewerken

Delen via


InstanceContext Constructors

Definition

Initializes a new instance of the InstanceContext class.

Overloads

InstanceContext(Object)

Initializes a new instance of the InstanceContext class for a specified object that implements the service instance.

InstanceContext(ServiceHostBase)

Initializes a new instance of the InstanceContext class for a service hosted by a specified host.

InstanceContext(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.

InstanceContext(Object)

Source:
InstanceContext.cs

Initializes a new instance of the InstanceContext class for a specified object that implements the service instance.

public:
 InstanceContext(System::Object ^ implementation);
public InstanceContext (object implementation);
new System.ServiceModel.InstanceContext : obj -> System.ServiceModel.InstanceContext
Public Sub New (implementation As Object)

Parameters

implementation
Object

The object that implements the service instance.

Examples

The following code shows how to construct an InstanceContext object by passing in a ServiceHost instance:

string info = "";

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

Console.WriteLine(info);

Remarks

This sets the service host associated with the instance context to null.

Applies to

InstanceContext(ServiceHostBase)

Initializes a new instance of the InstanceContext class for a service hosted by a specified host.

public:
 InstanceContext(System::ServiceModel::ServiceHostBase ^ host);
public InstanceContext (System.ServiceModel.ServiceHostBase host);
new System.ServiceModel.InstanceContext : System.ServiceModel.ServiceHostBase -> System.ServiceModel.InstanceContext
Public Sub New (host As ServiceHostBase)

Parameters

host
ServiceHostBase

The ServiceHostBase that hosts the service.

Exceptions

host is null.

Examples

The following code shows how to construct an InstanceContext object by passing in a ServiceHost instance:

string info = "";

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

Console.WriteLine(info);

Applies to

InstanceContext(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.

public:
 InstanceContext(System::ServiceModel::ServiceHostBase ^ host, System::Object ^ implementation);
public InstanceContext (System.ServiceModel.ServiceHostBase host, object implementation);
new System.ServiceModel.InstanceContext : System.ServiceModel.ServiceHostBase * obj -> System.ServiceModel.InstanceContext
Public Sub New (host As ServiceHostBase, implementation As Object)

Parameters

host
ServiceHostBase

The ServiceHostBase that hosts the service.

implementation
Object

The object that implements the service instance.

Examples

The following code illustrates how to create an InstanceContext object by first creating the service object and ServiceHost object:

Uri baseAddress = new Uri("http://localhost:8000/ServiceModelSamples/service");
CalculatorService service = new CalculatorService();
ServiceHost serviceHost = new ServiceHost(service, baseAddress);
InstanceContext instanceContext = new InstanceContext(serviceHost,service);

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

Applies to