1

I have developed a WCF Service that upon request, will create a worker thread and begin a sometimes extensive process of working with large amounts of data.

I require both this processing ability and the RESTful abilities of WCF Services to be able to be used.

Example: Storing a Thread Globally, and being able to access it in the RESTful Call.

However, from my understanding, doing this in IIS is not advised and IIS will terminate long-running applications, and it is advised to run this as a Windows Service hosted WCF Service.

Yet, we rely on the ability to use Web Deploy / Publishing via Visual Studio and is integral to our development process.

How can I have the best of both worlds?

Smarter
  • 19
  • 6

1 Answers1

0

Windows Services still have the same fundamental problem because you eventually have to deploy new code or restart the server (or, god forbid, have a crash!). The service will need to shut down.

You can mostly control when this happens with a Windows Service which is a good thing. But fundamentally you have to have a concept for that should happen with your long-running work in such a situation.

I think a well-tuned IIS app has almost no disadvantages compared to a Windows Service. There is just no way to run long-running work without interruption.

Deal with that fact. For example by restarting work and wrapping it in a transaction so that arbitrary interruptions do not cause data corruption.

usr
  • 168,620
  • 35
  • 240
  • 369
  • Scheduled down times are acceptable, random failures are not. When a user Starts the work, it needs to run until completion in the background. Are you saying that a Windows Service hosted WCF Service would continue to operate without issue until development caused otherwise? – Smarter Jun 30 '14 at 23:01
  • What can I tell you? Make sure to never ever have a bug :) You can pretty much eliminate all unscheduled reasons for shutdown in both IIS and WS. Read about the common issues and counteract them as much as possible. You still need a response to the situation where someone says `new Thread(() => ((string)null).ToLower())` and your process is killed without notice. Or, just the long-running work dies which appears to be not to your liking either. These things happen. – usr Jun 30 '14 at 23:05
  • For the sake of development ease, can you suggest a method of how to stop IIS from recycling my WCF Service while it's threads are running? – Smarter Jun 30 '14 at 23:07
  • The best you can do is search (https://www.google.com/webhp?complete=1&hl=en&gws_rd=ssl#complete=1&hl=en&q=asp.net+background+work). Maybe search for "wcf background work" as well. And test this under production conditions. Have long-running work for 8 days and make sure it still lives. – usr Jun 30 '14 at 23:08