What framework to use for RESTful Services in .net

后端 未结 5 1188
终归单人心
终归单人心 2021-01-30 14:33

I know that similar questions have been asked, but most of them are out of date. So here we go again :). I need to implement a complete REST service layer for our application. T

相关标签:
5条回答
  • 2021-01-30 15:07

    Been playing with Nancy myself lately and I'm also considering Manos de Mono. Here's the an example from the home page on Nancy.

    public class HelloModule : NancyModule
    {
        public HelloModule()
        {
            Get["/"] = parameters => "Hello World";
        }
    }
    
    0 讨论(0)
  • 2021-01-30 15:12

    If I was starting this today I would choose from your third option of doing something Custom in ASP.NET MVC3 or using one of the frameworks below.

    • WCF Preview 4
      • Its been re-written by Glenn Block
      • Here's a sample REST project RestBucks
    • OpenRasta
      • Demo application here
    0 讨论(0)
  • 2021-01-30 15:19

    I originally started ServiceStack because of the inefficiency (development and runtime) and friction imposed in creating web services with alternative .NET frameworks.

    3-4x Faster Json Serialization than MVC

    ServiceStack has a strong focus performance as we believe it provides the best end-user UX which is why it comes in-built with a strong set of Caching providers including the fastest JSON Serializer for .NET - 3-4x times faster than the serializers shipped with .NET and MVC (its default JavaScriptSerializer is the slowest in .NET). For max performance there's no runtime reflection or Regular Expressions used. It employs smart non-linear Route matching and you're recommended to use the much faster built-in Caching providers to work around the poor performance of ASP.NET's Session.

    Focused on typed, iterative, code-first development

    ServiceStack lets you develop strong-typed web services promoting best practices out-of-the-box using the minimum amount of code and automatically without any code-gen, config, pre/post build-steps, etc.

    Example of a simple Hello World service:

    public class Hello { public string Name { get; set; } }
    public class HelloResponse { public string Result { get; set; } }
    
    public class HelloService : IService 
    {
        public object Get(Hello request) 
        {
            return new HelloResponse { Result = "Hello, " + request.Name };
        }
    }
    

    With just these classes, all your web services are automatically made available in a variety of different formats (JSON, XML, JSV, CSV, SOAP) all out-of-the-box with zero effort.

    Example of Strong Typed Client API using C#:

    var client = new JsonServiceClient("http://localhost/Service");
    var response = client.Send<HelloResponse>(new Hello { Name = "World!" });
    

    JavaScript example using jQuery:

    $.getJSON("http://localhost/Service/hello/World!", function(r) {
        console.log(r.Result);
    });
    

    Development friendly

    Because visualizing web services is important when iteratively developing web services, the default Content-Type when viewing web services in a browser is a human friendly JSON HTML5 Report format (also available stand-alone at http://ajaxstack.com/jsonreport/) which enables you to visualize the response of your web services in a glance.

    You also get an automatically generated metadata page (that you can annotate with your own custom description) which serves as a great way to document your web service API.

    But what if they decided to stop development

    As the creator of ServiceStack I don't see myself abandoning development in the foreseeable future. I build systems with it daily simply because I find it's a cleaner, faster, more productive framework to develop with.

    Promotes best-practices

    There are very few .NET web services frameworks that promote a DTO-first message-based architecture enabling the Service Interface pattern - A web services best-practice commonly seen in the Java ecosystem making it easy to develop batch-full coarse grain SOA-based web services.

    There is 0 risk it will be abandoned in favour of another .NET web service framework. Simply because we don't believe any other .NET framework actively promotes web services best-practices (i.e. DTO / Remote Façade and Service Interface patterns) and a primary focus on performance.

    But even so as an Open Source project with nearly 20 contributors, this fear is mitigated. How many proprietary, closed-source frameworks have MS abandoned and forced everyone to move onto a successor? Open source software evolves, it doesn't get abandoned and rewritten.

    The entire source code for ServiceStack lives under http://github.com/ServiceStack there is no lock-in and GitHub makes it easy for anyone to fork and continue development as many have already done.

    Works everywhere

    Finally, ServiceStack can run on any ASP.NET host in IIS 6/7 on Windows or Linux/OSX using Mono. It also supports a stand-alone HttpListener host allowing you to run it without a web server, i.e. embedded in any Console or Windows application, inside a Windows Service and has even hosted inside a MonoTouch iPhone application.

    0 讨论(0)
  • 2021-01-30 15:20

    Thje Shoulders Of Giants solution is now available via CodePlex and NuGet... renamed as Resources Over MVC.

    0 讨论(0)
  • 2021-01-30 15:21

    For me, the easiest and cleanest solution would be to implement the services as controllers in ASP.NET MVC3 with methods that return a JsonResult.

    Advantages:

    • The MVC framework does the heavy lifting for you

    • You can implement the model validation using attributes instead of code

    • XCopy deployment to any version of IIS

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