Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a REST-Service in C# without the use of ASP.NET

Tags:

rest

c#

.net

I try to create a Text-To-Speech service in windows. The API should be exposed using a REST API. Unfortunately I only find examples using ASP.NET. Is it possible to create such a service without the use of ASP. Any hints or examples would be much appreciated.

I searched both google and stackoverflow; but could not find information or examples to achieve this.

like image 749
Patrik Gfeller Avatar asked Sep 16 '25 02:09

Patrik Gfeller


1 Answers

You can view the Networking\Writing an HTTP Server chapter in brothers' Albahari "C# 7.0 in a Nutshell" book.

It would be something like

HttpListener listener = new HttpListener();
listener.Prefixes.Add ("http://localhost:51111/MyApp/"); // Listen on 51111
listener.Start();

But it's definetly not the easiest way to do so. You'll have to write too much low-level code.

Just use web API with ASP.NET Core MVC. You can find more information here: https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-2.2&tabs=visual-studio

like image 69
Liam Kernighan Avatar answered Sep 17 '25 18:09

Liam Kernighan