InstanceContext 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 InstanceContext 类的新实例。
重载
InstanceContext(Object) |
为实现服务实例的指定对象初始化 InstanceContext 类的新实例。 |
InstanceContext(ServiceHostBase) |
为指定主机承载的服务初始化 InstanceContext 类的新实例。 |
InstanceContext(ServiceHostBase, Object) |
为实现服务实例并且由指定主机承载的指定对象初始化 InstanceContext 类的新实例。 |
InstanceContext(Object)
为实现服务实例的指定对象初始化 InstanceContext 类的新实例。
public:
InstanceContext(System::Object ^ implementation);
public InstanceContext (object implementation);
new System.ServiceModel.InstanceContext : obj -> System.ServiceModel.InstanceContext
Public Sub New (implementation As Object)
参数
- implementation
- Object
实现服务实例的对象。
示例
下面的代码演示如何通过传入 InstanceContext 实例构造 ServiceHost 对象。
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);
注解
这将与实例上下文关联的服务主机设置为 null
。
适用于
InstanceContext(ServiceHostBase)
为指定主机承载的服务初始化 InstanceContext 类的新实例。
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)
参数
- host
- ServiceHostBase
承载服务的 ServiceHostBase。
例外
host
为 null
。
示例
下面的代码演示如何通过传入 InstanceContext 实例构造 ServiceHost 对象。
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);
适用于
InstanceContext(ServiceHostBase, Object)
为实现服务实例并且由指定主机承载的指定对象初始化 InstanceContext 类的新实例。
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)
参数
- host
- ServiceHostBase
承载服务的 ServiceHostBase。
- implementation
- Object
实现服务实例的对象。
示例
下面的代码演示如何通过先创建服务对象和 InstanceContext 对象来创建 ServiceHost 对象:
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);