Building a C# Web API - REST

后端 未结 5 1418
醉酒成梦
醉酒成梦 2021-02-06 08:01

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.

相关标签:
5条回答
  • 2021-02-06 08:41

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

    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.

    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.

    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.

    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

    0 讨论(0)
  • 2021-02-06 08:46

    If you think WCF might be overkill you could implement a simple ASP.NET MVC application that returns data as JSON or XML.

    http://omaralzabir.com/create_rest_api_using_asp_net_mvc_that_speaks_both_json_and_plain_xml/

    update: Another excellent option is ServiceStack. I've used it and it's really nice to work with.

    0 讨论(0)
  • 2021-02-06 08:46

    For a simple Web API, WCF is overkill, clunky, operation orientated and designed for SOAP based services (it does Web HTTP, but that was an afterthought).

    The new kid on the block is ASP.NET MVC Web API for lightweight web-orientated architectures. Prepare to see more and more of this young upstart.

    0 讨论(0)
  • 2021-02-06 08:51

    You really need to take a look to the WCF Data Services they are easy to implement

    http://msdn.microsoft.com/en-us/data/bb931106

    I first met them when I implemented the Dino Esposito examples in March 2010 MSDN Magazine http://msdn.microsoft.com/en-us/magazine/ee336022.aspx

    I recommend you first read the Dino Example.

    0 讨论(0)
  • 2021-02-06 08:53

    You could look into vanilla web services. I only briefly glanced at it, but this seems like a decent guide.

    0 讨论(0)
提交回复
热议问题