4

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.

5
  • What do you mean by "without ASP.NET"? In which language do you want the server code to be written with? If it's C#, then that's ASP.NET - if not, well, why using C# in the first place? Commented May 19, 2019 at 10:38
  • 1
    @ShayLivyatan Not really, WCF exists and so do many others open source alternatives Commented May 19, 2019 at 10:42
  • 1
    You can create a REST service in C# that is self-hosted, e.g. contained in for example a .NET executable that you can launch (or a Windows service that runs in the background). It will however still probably be the simplest to use ASP.NET Web API to create this service - but there are non-ASP.NET open source alternatives, if you really want to avoid any ASP.NET bits, for instance Service Stack Commented May 19, 2019 at 10:44
  • @CamiloTerevinto WCF - that's a valid point, but as for other open-source alternatives, I was under the impression OP is trying to write such a service in C# using Visual Studio, but maybe I got the wrong impression. Commented May 19, 2019 at 10:48
  • 1
    You could use Nancy, or ServiceStack, but I wouldn't. Start by explaining why you don't want to use ASP.NET. Commented May 19, 2019 at 10:50

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

4 Comments

Hi Liam, thank you for your reply. I tried to follow the tutorial you've linked. But somehow I can not get it to work. I created an ApiController class with a method decorated with [HttpGet] - but it is never called. I suspect that I have to configure routing (MapHttpRoute), but can not figure how I can direct all URL's to my method. with kind regards
@PatrikGfeller Maybe there are really some issues with your route mapping. You can look for example at github.com/liamkernighan/simple-webapi or just find some other tutorials on medium.com. There are two valid routes in readme.md after you build the project.
I downvoted the answer because the question was "without ASP.NET" and your answer concluded with "Just use web API with ASP.NET"
@Piranha and there is an actual answer, if you look a little bit higher. Might be a surprise, but I'm not forcing anyone at gunpoint to use Asp.Net.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.