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);