C# 中的 RESTful API 服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16749637/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 01:50:39  来源:igfitidea点击:

RESTful API Server in C#

c#apirest

提问by BytesGuy

Are there any frameworks that allow a RESTful API Server to be written in C#?

是否有任何框架允许用 C# 编写 RESTful API 服务器?

I have seen MVC 4, however this seems to be providing a view that you can see in the browser, I just require the API server and no view. It would be great if it was able to provide a streaming API too.

我见过 MVC 4,但是这似乎提供了一个您可以在浏览器中看到的视图,我只需要 API 服务器而不需要视图。如果它也能够提供流媒体 API,那就太好了。

Thanks

谢谢

采纳答案by Ahmed Magdy

If you are using .NET Framework 4.5 you can use Web API

如果您使用的是 .NET Framework 4.5,则可以使用Web API

If you are using .NET Framework 3.5 I highly recommend ServiceStack

如果您使用 .NET Framework 3.5,我强烈推荐ServiceStack

If you are using .NET Core then you can use ASP.NET Core Web API

如果您使用的是 .NET Core,那么您可以使用ASP.NET Core Web API

回答by Scott Offen

If you are working in .NET 4.0 or higher and looking for a pre-existing REST server solution that you can plug into (which it sounds like you are), you might want to check out Grapevine. You can get it using NuGet, and the project wikihas lots of sample code.

如果您在 .NET 4.0 或更高版本中工作,并且正在寻找可以插入的预先存在的 REST 服务器解决方案(听起来像您一样),您可能需要查看Grapevine。您可以使用 NuGet 获取它,项目 wiki有很多示例代码。

I am the project author, and I had a similar need as the one you described. Using resources I found here and elsewhere, I built Grapevine so that I would have a solution in my back pocket whenever I needed it again (DRY).

我是项目的作者,我和你描述的有类似的需求。使用我在这里和其他地方找到的资源,我构建了 Grapevine,这样当我再次需要它时,我的后口袋里就有一个解决方案 ( DRY)。

回答by Ran Sasportas

You can use web api, it is part of the .net MVC framework but it is relying on the razor engine (inly if you use the mvc templating engine cshtml).

您可以使用 web api,它是 .net MVC 框架的一部分,但它依赖于 razor 引擎(仅当您使用 mvc 模板引擎 cshtml 时)。

If you are using .net 4.0 you can use web api 1, If you are you .net 4.5 you can use web api 2

如果您使用的是 .net 4.0,则可以使用 web api 1,如果您使用的是 .net 4.5,则可以使用 web api 2

回答by Alex

Nancyis a free REST framework for C#.

Nancy是一个免费的 C# REST 框架。

回答by tatmanblue

If you are ok with using IIS to host your app, WebAPI is the route to go, per the above answers. Not every solution is best in IIS however.

如果您同意使用 IIS 来托管您的应用程序,那么根据上述答案,WebAPI 是您要走的路线。然而,并非每个解决方案在 IIS 中都是最好的。

For executable apps (such as a windows service), consider using WebServicesHost. This pageis a good example of how to implement it.

对于可执行应用程序(例如 Windows 服务),请考虑使用WebServicesHost这个页面是如何实现它的一个很好的例子。