开发者

Any recommendations to host a WCF service?

Have a winform application and want to开发者_运维知识库 host a WCF service inside it. Do I need to host it in a seperate appdomain? Any recommendations?


You don't need to host it in separate domain but you must decide if you want service request to be processed by UI thread or different thread. It depends on the way you create ServiceHost instance or on ServiceBehavior applied to your service class.

When service is hosted in UI thread it can directly interact with UI but request processing is part of message loop and all service requests are processed by single thread (sequentially). When request is processed no other windows event (including UI events) can be processed = application freezes.

When service is hosted in different thread it behaves as in any other hosting environment but it can't directly interact with UI - you must use delegate invocation.

Ways to enforce service to run in own threads:

  • Create and open ServiceHost instance before you call Application.Run (start of Windows message loop)
  • Create and open ServiceHost instance in separate thread
  • Use [ServiceBehavior(UseSynchronizationContext = false)] on your service implementation


No, you don't have to host it in a separate AppDomain. Just host it. There's nothing terribly special about WinForms in this regard.


What's your app do? Is the service a part of the apps regular functions or a completly seperate logical entity?

If you want to be loading and unload resources (such as assemblies) related to your service without shutting your app down a seperate app domain would make this much easier, but otherwise I don't see much of a reason to complicate things.

Just my 2c. :-)


You can host in Win form but you have to keep it running throughout.

Also suggest you to host in IIS so any type of client avail your service.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜