构建一个C#的Web API - REST [英] Building a C# Web API - REST

查看:116
本文介绍了构建一个C#的Web API - REST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要开始在C#中的一个项目。我从来没有使用C#和我希望我能得到一些实施意见之前,我做一个愚蠢的错误,并往下走错误的道路。

I am about to start a project in C#. I've never used c# and I was hoping I could get some implementation advice before I make a silly mistake and go down the wrong path.

我想实现基本上是具有可以通过一个Web API来访问服务器上的C#应用​​程序。此应用程序将在一些字符串变量,然后返回一个字符串。该应用程序将打开并运行一些安装的程序(不是C#程序)。

What I am trying to achieve is basically having a C# application on a server that can be accessed via a Web API. This application will take in some string variables and then return a string. The application will be opening and running some installed programs (not c# programs).

我读过有关的WCF,但我认为在乍看之下,这可能是矫枉过正,因为我希望创造只会有一个或两个请求方法,并返回一个字符串的API。

I've read about WCF but I think at first glance this might be overkill as the API I am hoping to create will only have one or two request methods and will return a string.

我所真正需要的是我应该使用,要寻找什么成什么意见,甚至联系到很好的教程与C#构建Web服务,以及如何我可以做一个C#应用程序的Web API之间的联系。

What I am really looking for is advice on what I should be using, what to look into and even links to good tutorials on building web services with C# and how I can make the link between a web API to a C# app.

感谢所有的任何建议。

推荐答案

跳过WCF和ASMX。相反,刚刚经历的通用处理器(ashx的)文件执行这种东西。

Skip wcf and asmx. Instead just implement this stuff through generic handlers (.ashx) files.

您必须在什么进来,出去,而不必淤泥与周围所有的XML垃圾的完全控制。我们这样做了一段时间后,并没有回头。

You have complete control over what comes in and goes out without having to muck around with all the XML garbage. We did this a while back and haven't looked back.

总之,我会使用WCF如果我的终点是会比web服务器以外的东西。我会使用ASMX如果我必须提供所有的答复早在XML和我保证只是.NET客户端将访问它。

In short, I'd use WCF if my endpoints were going to be something other than the web server. I'd use asmx if I had to deliver all of the responses back as XML AND I was assured only .net clients would be accessing it.

通用处理器是一样的.aspx页面,但没有所有的页面生命周期的开销。它可以让你得到那个可以访问所有的HTTP POST和查询字符串变量的上下文对象,它是由你来决定什么发出回来。

Generic handlers are like .aspx pages but without all of the overhead of the page lifecycle. It gives you get a context object that has access to all of the http post and query string variables and it's up to you to decide what to emit back.

他们是实现简单,有没有的再那是什么配置设置的呢?的问题。

They are simple to implement and have none of the "what was that config setting for again?" issues.

这里有几个pretty好的演练:结果
<一href=\"http://swindelles.com/2008/07/11/creating-rest-web-services-in-c-sharp/\">http://swindelles.com/2008/07/11/creating-rest-web-services-in-c-sharp/

<一href=\"http://www.$c$cproject.com/KB/aspnet/RestServicesInASPNET2.aspx\">http://www.$c$cproject.com/KB/aspnet/RestServicesInASPNET2.aspx

Here are a couple pretty good walkthroughs:
http://swindelles.com/2008/07/11/creating-rest-web-services-in-c-sharp/
http://www.codeproject.com/KB/aspnet/RestServicesInASPNET2.aspx

这篇关于构建一个C#的Web API - REST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆