Reputation: 1193
I've created a simple WCF service which is hosted within a windows service. WCF service is automatically started on windows service start, but when I connect to the WCF service from a client for the first time it takes a couple of seconds (as any other WCF service).
I'm aware on how to avoid this delay when the service is hosted on IIS, but not when it's hosted within anything else.
To be exact:
Is there a way to wake-up the WCF service which is hosted within a windows service without a client reqest being made to it? Possibly from the windows service code?
Upvotes: 2
Views: 620
Reputation: 31780
With IIS hosting, the delay is not because the WCF service needs to "wake up". The reason this happens in IIS hosting is that IIS will unload the app pool from memory after a period of inactivity (or due to some other internal state). This does not apply with windows service hosting.
The delay you are experiencing is likely because when your client calls the service for the first time it must spin up a wcf channel to make the call. Subsequent calls can then be made using the same channel so there is no lead time.
To prevent this behavior you must keep the channel open all the time. There are several ways to do this, but the simplest is to use sessions. See Erik Funkenbusch's excellent answer for more information. However, you should consider if you absolutely need this, as sessions are an overhead and don't scale well.
Upvotes: 3