22

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?

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
Jason Swager
  • 6,421
  • 6
  • 41
  • 56

7 Answers7

15

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

Paulo Santos
  • 11,285
  • 4
  • 39
  • 65
  • 2
    This looks very promising. The Self Hosting chapter in particular answers my question of standalone EXE/service. Thanks. – Jason Swager Jun 18 '09 at 17:48
5

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
  • 554,122
  • 78
  • 1,158
  • 1,373
  • 2
    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 Jun 18 '09 at 17:16
3

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
  • 4,702
  • 1
  • 27
  • 19
1

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

Grokys
  • 16,228
  • 14
  • 69
  • 101
1

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
  • 53,070
  • 5
  • 41
  • 38
1

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.

1

This question is somewhat older but since I needed something similar some time ago it felt like this question is still relevant.

I wrote a small Rest-API with NancyFx and OWIN. OWIN is a standard interface between .Net applications and web servers. With OWIN it is possible to create a self-hosted WEB-API. Nancy on the other hand is

a lightweight, low-ceremony, framework for building HTTP based services on .NET ¹

The combination of those two makes it possible to create a self-hosted C# Web service. I am quite sure that there are many more possibilities to create something like this by now but since I used it like this I thought the Information might be useful to someone.

Bongo
  • 2,933
  • 5
  • 36
  • 67