views:

1422

answers:

6

Is it possible to create a C# EXE or Windows Service that can process Web Service requests? Obviously, some sort of embedded, probably limited, web server would have to be part of the EXE/service. The EXE/service would not have to rely on IIS being installed. Preferably, the embedded web service could handle HTTPS/SSL type connections.

The scenario is this: customer wants to install a small agent (a windows service) on their corporate machines. The agent would have two primary tasks: 1) monitor the system over time and gather certain pieces of data and 2) respond to web service requests (SOAP -v- REST is still be haggled about) for data gathering or system change purposes. The customer likes the idea of web service APIs so that any number of clients (in any language) can be written to tap into the various agents running on the corporate machines. They want the installation to be relatively painless (install .NET, some assemblies, a service, modify the Windows firewall, start the service) without requiring IIS to be installed and configured.

I know that I can do this with Delphi. But the customer would prefer to have this done in C# if possible.

Any suggestions?

+2  A: 

Yes, it is possible (and fairly easy).

Here is a CodeProject article showing how to make a basic HTTP server in C#. This could easily be put in a standalone EXE or service, and used as a web service.

Reed Copsey
This example definitely shows how to embed a web server, but nothing on how to get turn an incoming request into a web service method call. I could write a SOAP packet parser that creates the necessary object, locates the method and calls it with the various properties, but I'm guessing that some where in .NET, all of this could be done.
Jason Swager
+1  A: 

One technology you might want to check out is WCF. WCF can be a bit of a pain to get into but there's a great screencast over at DNRTV by Keith Elder that shows how to get started with WCF in a very simple fashion.

http://www.dnrtv.com/default.aspx?showNum=135

Antonio Haley
Actually, Antonio, WCF is even less painful that Web Services.
Paulo Santos
WCF _is_ web services. You may be thinking of the old way to do web services.
John Saunders
+1  A: 

Yes, it's possible, you may want to have a look at WCF and Self Hosting.

Paulo Santos
This looks very promising. The Self Hosting chapter in particular answers my question of standalone EXE/service. Thanks.
Jason Swager
A: 

You could take a look at HttpListener in the .Net framework.

Groky
That gives me a simple web server - but nothing to handle web service requests.
Jason Swager
A: 

I would highly recommend WCF. It would fit very well into a product like you are describing. There are a good number of books available.

AgileJon
A: 

Sure, you can do that. Be sure to change the Output Type of the project to Console Application. Then, in your Main function, add a string[] parameter. Off of some switch that you receive on the command line, you can branch to ServiceBase.Run to run as a Windows Service or branch to some other code to run a console application.

W. Kevin Hazzard