3

In short, i am looking for the best mehod to provide a REST or SOAP API Server in a .Net Framework application (e.g. windows forms) - without admin rights in some cases

What is currently the best way of providing a web based REST or SOAP API in a possible portable csharp application? Basically i need something that supports the basic http standards out of the box (e.g. Expect: 100-continue and others) and at the same time is able to instanciate the classes of my csharp program directly (perfomrance and ease of use reasons).

The microsoft way is to either use IIS and possibly ASP or go for httplistener. IIS could never be run in a portable way and requires lots of installation procedure/system administration based work. httlistener on the other hand is not even close to being a webserver, i would need to implement all the standard webserver commands on my own.

I am looking around for this topic since years now, one example is this question [old question] Alternative to HttpListener?

Unfortunately this one links to a discontinued project.

Any ideas?

[EDIT] The question targets not only C# but also .NET Framework 2-4.5. The result should be useable in e.g. Windows Form, Windows Service and Commandline applications.

Currently i am using a skeleton Webserver based on HTTPListener and therefore i need to implement all the Parsing of a request, formatting of answers and reacting to special http commands on my own (which seems to be a never ending task): https://www.codeproject.com/Articles/17071/Sample-HTTP-Server-Skeleton-in-C

Harry
  • 1,233
  • 10
  • 24
  • 1
    It is a shopping question, use google to find hits. ".net embeddable web server" shows Nancy, NHttp, Kayak, EmbedIO. Node.js is the big dog, so you want to also google "node.js .net integration". Out pops edge.js – Hans Passant Nov 03 '17 at 00:25
  • Make sure you write that as an answer before the bounty ends ;-) – Harry Nov 03 '17 at 06:25
  • 1
    REST and SOAP are totally different beasts. REST is ... almost nothing so HttpListener should suffice. Full blown SOAP (and WSDL) is complex and kinda old fashioned. So the two requirements are somehow contradictory. HttpListener doesn't need admin rights, only if what you do exposes your machine. For example, do you want to open your server to the outside, or is it just for localhost (https://stackoverflow.com/questions/223063/how-can-i-create-an-httplistener-class-on-a-random-port-in-c/) ? If you want more than localhost you will need to open the firewall anyway – Simon Mourier Nov 03 '17 at 08:13
  • @Simon thanks for your attention. I currently drive with HttpListener and a very simple rest api and discover problems every there and where. Some messages nulled out, some http clients sending strange http standard messages like expect continue etc. All this would not happen using a standard webserver like apache. Unfortunately there is no way to combin a .net application and apache natively. Then regarding soap or rest: it is an OR, i'll correct this in my question. – Harry Nov 03 '17 at 18:16
  • @Hans Passant i would really like your comment as an answer. You teached me about shopping questions, it might be too late for this question but i'll do a better job next time. I guess a list of requirements is a good start. I love your node.js integration, that might be my solution. All others i already tried. – Harry Nov 03 '17 at 18:19
  • @Harry - Note there is also this http://www.ultidev.com/Products/UWS-Cassini-Pro/Default.aspx (I'm no affiliated), which I think derives from the old "cassini web server". Could be interesting. – Simon Mourier Nov 03 '17 at 18:52
  • @Hans Passant i really would like to have your first comment as an answer, especially because of the "shopping question" part (also the other part is a very good advice) – Harry Nov 06 '17 at 22:41
  • I cannot reasonably post an answer like that. You'll use it once and get on with your project, I'll have to support that answer for the rest of my natural life and keep it updated when the shopping options change. They always change. Just use it. – Hans Passant Nov 06 '17 at 22:53
  • Thanks to Hans, i dont really understand your concerns but ok. @Simon Mourier , same request to you: you did invest some brain into my request so please go and get the credits – Harry Nov 07 '17 at 19:41

4 Answers4

2

You could try Griffin web server. I've used it for embedding a web server into applications to host a simple web interface, file hosting, and to provide a REST API for my application.

The biggest advantage for me versus the embedio project (which is excellent) is that it doesn't require admin privileges to run. Looks like no SOAP integration out of the box though.

cjmurph
  • 839
  • 7
  • 11
1

You should be able to do what you want using .NET Core. You can fairly easily build a self-hosted API using it that's independent of IIS. Tutorials should be easy to find, and here is a Microsoft example.

ilikesleeping
  • 600
  • 5
  • 14
  • Thanks! I looked up .NET Core but i am not certain it is combineable with .NET framework. I'd need a solution for the good old .net Framework. – Harry Oct 19 '17 at 12:26
1

As ilikesleeping suggested you could use dotnet core, but there are complications in making it work as a service.

I suggest you to use Microsoft OWIN framework. It's really simple and straightforward way of building restful applications. It can work fine as Console or a service, and of course in Console mkode you can display a Form should you wish to.

Here are some links to get kickstarted: https://learn.microsoft.com/en-us/aspnet/web-api/overview/hosting-aspnet-web-api/use-owin-to-self-host-web-api | https://learn.microsoft.com/en-us/aspnet/aspnet/overview/owin-and-katana/getting-started-with-owin-and-katana | https://blog.decayingcode.com/post/Creating-a-Self-Hosted-OWIN-Application/ | https://weblogs.asp.net/fredriknormen/creating-a-simple-rest-like-service-with-owin-open-web-server-interface

EDIT: ...and here's the topic on how to have a middleware that hosts SOAP endpoint over OWIN: Any way to get OWIN to host a SOAP service?

Mike Makarov
  • 1,287
  • 8
  • 17
0

I am the author of this question. Just wanted to make obvious for future readers what i learned here:

Most interesting about this question is that it is a "shopping" question. The accepted answer cannot be based on facts but on subjective feeling only. Most of the suggested methods hit the described usecase.

This is the reason why some users did not want to write an answer but instead put their suggestions in a comment instead. Strange but this is how SO works. We just prefer scientifically correct answers here!

By te way, this was my first "bounty" question. I am active SO user since about 3 weeks. (passive for years, like most people)

Harry
  • 1,233
  • 10
  • 24