开发者

Warming up a self-hosted WCF service

I've seen several articles on warming up a WCF service when it is hosted in IIS (that is, pre-loading caches, loading plug-ins e开发者_StackOverflow中文版tc - basically all the expensive stuff you don't want your users to be hanging around for when they issue their first request), but I haven't seen anything equivalent for when WCF is self-hosted in a .NET service.

Has anyone been able to achieve this?


If you're hosting your service, than you can create a client (i.e., using ChannelFactory<T>) to the service right after you call ServiceHost.Open and issue a "ping" request; that way if the service implementation is doing some heavy loading, it can happen right then, instead of when the first "real" client request arrives.


After the host is opened, the types are loaded and you are ready to go. From my experience, the delay is usually creating the client channel. The expensive part is creating the Channel Factory, so I prefer to create that up front and use GetChannel() for my calls. You'll also have to negotiate security the first time you connect, so you can adjust those setting to find the right balance.

I believe when you are in IIS you are using the WAS service. The main feature of that service doesn't keep the host open all the time, so you are not using resources for every idle service, thus requiring time to load the assembly when it is needed. Self hosting allocates all the resources to your service and host as soon as it is started.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜