Прочитај на енглеском Уреди

Делите путем


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
Source:
InstanceContext.cs

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

C#
public InstanceContext(object implementation);

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:

C#
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

.NET Core 1.1 и друге верзије
Производ Верзије
.NET Core 1.0, Core 1.1
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
UWP 10.0

InstanceContext(ServiceHostBase)

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

C#
public InstanceContext(System.ServiceModel.ServiceHostBase host);

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:

C#
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

.NET Framework 4.8.1 и друге верзије
Производ Верзије
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

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.

C#
public InstanceContext(System.ServiceModel.ServiceHostBase host, object implementation);

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:

C#
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

.NET Framework 4.8.1 и друге верзије
Производ Верзије
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1