3

I've just created a simple asp.NET web service application with a WebMethod that passes the current server time and a Windows form application to run alongside this as a client.

As it stands, for the client app to be able to interact with the server app, the web service application needs to be running (runs in a web browser). If the browser is then closed, the client app cannot talk to the web service app.

Ideally, I would need this web service to always be running in the background on my server at all times (not just when a web browser is opened) and start when the server is booted up.

What would be the best way to achieve this? I have minnimal experience with asp.NET so is there a way to configure the web service to be a background service? Do I need to create a seperate Windows service application that uses asp.NET web services?

Any help appreciated, thanks.

Paul Alexander
  • 2,686
  • 4
  • 33
  • 69
  • Hey Paul... Have you deployed the web service to an IIS server? Or are you only running it on your local work-station via Visual Studio? – Casey Crookston Oct 08 '19 at 15:11
  • Just running it locally from Visual Studio at the moment. – Paul Alexander Oct 08 '19 at 15:16
  • 1
    Ok, so then the answer by CodeCaster is correct. In order for it to be always available, you will need to deploy it to an IIS server that is publicly available. (Or at least, where it is available on the same network where the clients can access it.) – Casey Crookston Oct 08 '19 at 15:19
  • 1
    To answer your last question: No, you do not need to create a separate Windows service application. Your web service is literally just a website, so you'll set it up in IIS as that. – Casey Crookston Oct 08 '19 at 15:20

1 Answers1

2

Yes, by default, Visual Studio stops debugging your web application when you close the browser used for debugging... But you shouldn't run your application from Visual Studio. You deploy web applications to IIS. Then they'll start when the machine starts, and they don't need a browser to keep running.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • Oh okay, I wasn't aware of that. So VS just uses the browser as a debugging tool. Could you explain how you would deploy the web app to IIS? Thanks for your help. – Paul Alexander Oct 08 '19 at 15:18
  • @PaulAlexander, if you need help deploying to IIS, that would be outside the scope of this question. First, spend some time on Google. There are a LOT of tutorials and articles on how to do this. If you get stuck, come back and ask another question. – Casey Crookston Oct 08 '19 at 15:25
  • Ok will do. Thank you very much for your help. – Paul Alexander Oct 08 '19 at 15:31
  • 2
    @PaulAlexander VS doesn't really use the browser as a debugging tool. I believe it just monitors the process to see if it exits. If it exits, it assumes you want to stop the web server (typically a mini version of IIS called IIS Express) and the debugging session. This choice was likely made because Visual Studio is a development tool and isn't intended to keep an app always running or to be deployed on production boxes. That's what full IIS is for. – mason Oct 08 '19 at 15:48