ServiceHost States and Transitions

The ServiceHost class implements a finite-state machine. A ServiceHost object can be in one of a small number of states, and there are well defined rules that determine how the WCF runtime transitions a ServiceHost object from one state to another. Some of these transitions occur as the result of specific method calls, while others are caused by exceptions in the service, in the communications infrastructure, or in the objects implementing the channel stack. A service host application should be prepared to handle these transitions and attempt recovery to ensure that the service is available whenever possible.

 

Created State: When you instantiate a ServiceHost object, it starts in the Created state.In this state,you can use the AddServiceEndpoint method to cause the ServiceHost object to listen for requests on a particular endpoint. A ServiceHost object in this state is not ready to accept requests from client applications.

 

Opening State: Start a ServiceHost object listening for requests by using the Open method (or the BeginOpen method if you are using the asynchronous programming model). The ServiceHost object moves to the Opening state while it creates the channel stacks specified by the bindings for each endpoint and starts the service.

 

Faulted State: If an exception occurs while trying to open the ServiceHost , the object transitions to the Faulted state.

 

Opened State: If the ServiceHost object successfully opens the communication channels for the service, it moves to the Opened state.Only in this state can the object accept requests from client applications and direct them to the service.

 

Closing State: You stop a ServiceHost object from listening for client requests by using the Close (or Begin-Close) method. The ServiceHost object enters the Closing state. Currently running requests are allowed to complete, but clients can no longer send new requests to the service.

 

Closed State: When all outstanding requests have finished, the ServiceHost object moves to the Closed state.

 

Aborted State: You can also stop a service by using the Abort method. This method closes the service immediately without waiting for the service to finish processing client requests.

 

Stopping or aborting the service disposes the service object hosted by the ServiceHost object and reclaims any resources it was using.

 

 

WCF States Transitions

State transition diagram for the ServiceHost class

转载于:https://www.cnblogs.com/fast-michael/archive/2011/12/22/2298060.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值