InstanceContext.ReleaseServiceInstance 方法

定义

释放服务实例。

public:
 void ReleaseServiceInstance();
public void ReleaseServiceInstance ();
member this.ReleaseServiceInstance : unit -> unit
Public Sub ReleaseServiceInstance ()

例外

该服务实例处于已创建或打开状态并且不能使用。

该服务实例已中止。

该服务实例正在关闭或已关闭并且无法修改。

该服务实例处于错误状态,并且在这些状态下无法修改。

示例

Uri baseAddress = new Uri("http://localhost:8000/ServiceModelSamples/service");

// Create a ServiceHost for the CalculatorService type and provide the base address.
using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress))
{
    serviceHost.Open();
    OperationContext operationContext = OperationContext.Current;
    InstanceContext instanceContext = operationContext.InstanceContext;
    instanceContext.ReleaseServiceInstance();
}

适用于