开发者

Open close ServiceHost multiple times

I am trying to figure out how to open and close a ServiceHost object multiple times in a self-hosted WCF app:

what I did: 1. create ServiceHost object

  1. call Open()
  2. call Closed() so far so good.
  3. call Open() again, exception: Cannot access a disposed object, which is because CommunicationObject is disposed , makes perfect sense.

How can I open the ServiceHost again in this case without recreating that object again (rather, I'd recreate CommunicationObject if it is pos开发者_StackOverflow社区sible).

Thanks in advance.


ServiceHost inherits from CommunicationObject. ServiceHost is the CommunicationObject throwing the exception. Once a CommunicationObject is Closed it cannot be reopened. You'll have to create a new ServiceHost.

The CommunicationState state machine:

Every object starts in the Created state and proceeds in a one-way progression through the Opening, Opened, Closing, and Closed states.


I'm not sure what you end goal is but take a look at this article. http://www.codeproject.com/KB/WCF/generic_wcf_host.aspx If that's not the problem you're trying to skin then maybe some of the technicals and application domains is what you are looking for?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜