How to force startup of WCF service - wcf

I have an IIS hosted WCF service, and a client Windows application which, upon the first use of the day, takes a while to respond to the first service call. I believe this to be because IIS shuts down services which are not used for a period of time (and the delay is the restart time for the service). I was wondering whether I could alleviate this by making an asynch call when my application starts up (just to, potentially, get the service to start). I therefore, upon application start, created a "fire and forget" background thread which just opens a connection to the service. The intention being that when my application has finished its own startup, and wants to use the WCF service, the thread will (probably) have finished and the service startup delay will not be encountered by the user.
Is this reasonable ? Is opening a channel to the WCF service enough, on its own, to start the service, or do I need to write some dummy method and call that ?
Thanks
Ross

Check if you really want your app to handle this task and checkout the AppWarm-Up Module for IIS, maybe you can use this without adding code to your serivce.

Is this reasonable ?
It doesn't sound like a good approach to me. If you have control over how the service is hosted I would advise you to self-host it.

Related

Background worker with silverlight 5 makes wcf service calls stuck while running

I am working with Backgorund worker. I have a Silverlight 5 application using WCF service.
When I call a background method it hits a service and this method takes some times to complete. During the time background worker is running, if i make some other service call it stops till the background method gets completed. I want to make parallel WCF service calls. I am not sure about the reason of the problem.
If your WCF is hosted in IIS, then the most probable cause of your second request not getting processed until the first WCF call is returned is the session lock put by IIS.
One way is to avoid using session for the processing or replacing with a custom session mechanism, as suggested in the above link.
If you provide more details about what your Background worker is trying to achieve, you might get a more targeted answer (i.e. maybe the processing can be done without locking the session).

WCF Service only works for the first call

We are developing a WCF Service that's called from a windows client.
The first time the Client calls the service we get a response but the second call times out.
Once we recycle the application pool or restart the service it works for another call.
It almost looks like the service dies but we are logging all exceptions on the server and there are no indications that the service errors out...
Any suggestions are greatly appreciated.
Thanks for the replies...
We found and fixed the problem:
we are using a thread method to post notifications form the web service to another web service. Since we experienced performance problems when running the service we limited the ThreadPool.MaxThreads, after removing that limitation the service works as expected.

Windows Services & WCF

I need to create a Windows Service to watch a folder on our network and action files that are placed within it. The process is quite slow and I need the ability to check the progress from a client application (which will be running in about 10 places on the same network as the machine running the Windows service).
Is hosting some WCF service in the windows service the right way to go about this and if so, are there any resources on how I would do this?
Thanks!
it seems a reasonable approach to me.
you can get details of how to host a WCF service inside a windows service in the MSDN how to
This code project page also has an example.
you might need to debug start up issues with the service, and I find adding a
Debugger.Launch();
to the beginning of the OnStart method is the easiest way of doing that. it enables you to debug through the start up process of your service and see any exceptions that occur.

Periodic operations in a Self-Hosted WCF Service using Timers

I know that it is not a good idea to have timers inside a WCF service class that is hosted inside IIS since these are meant to have short lifetimes. And from the advice here it also sounds like having a service is the best way to go for that situation.
But has anyone tried using timers inside a self-hosted service in production? We have a windows service that acts as a client and uses timers to do periodic operations at the moment.
This is fine for most cases, but I am concerned about the robustness of the design: some of the operations are critical (financial system calculation triggers). Since the WCF service and the windows service are two components, ensuring both are running is difficult.
If I moved the critical operations to a timer inside the WCF Service I remove that problem, but what else should I be concerned about then?
If I understand correctly, your question is actually about IIS-hosted WCF services, is that right?
IIS controls the application pool that your WCF service runs in. That means that IIS may decide to recycle your application pool and all the apps/services in it. Then your service only gets activated again once it is called by a client. So, scheduling in WCF services or ASP.NET applications cannot be relied on.
The picture of course changes if you can self-host your WCF service. Then there is no IIS application pooling to take into account, and you can schedule at will. Therefore, if you need the combination of WCF + scheduling, it's best to create a Windows service that will include both.

Gracefully terminate WCF Service - complete all open sessions and restrict new sessions

I have a WCF Service that I have written, which is hosted within a Windows service. It is operating in PerSession mode. The service permits clients to open files, make changes to files and close files remotely through the service. So far all works very smoothly.
When the Windows service is stopped, I would like to be able have the WCF Service not accept any new sessions and yet allow already connected clients to complete their current sessions and work (within a reasonable period/timeout).
What would be the best way to accomplish this?
Basically, calling ServiceHost.Close() will accomplish this - it will let all currently running request run to completion, but new request are being rejected will the orderly shutdown is in progress.
There's a "CloseTimeout" setting on your binding that you configured for your service - that controls how long the WCF runtime will allow running requests to take until they've properly shut down. If that timeout happens, the still running requests will be killed.
The ServiceHost.Abort() method on the other hand is the digital equivalent of a sledgehammer - all running requests are terminated at once, and the host is shut down.
ON the client side, you have the same .Close() and .Abort() methods on your client proxy which behave the same way.