How to achieve high-performance REST API on Azure with .NET?

后端 未结 7 1657
Happy的楠姐
Happy的楠姐 2021-02-07 15:24

We have a .NET Web Role hosted on Windows Azure that only serves a REST API with only a hand few web methods.

API is u

7条回答
  •  终归单人心
    2021-02-07 15:52

    Here are Benchmarks for different .NET serialization options

    Out of all JSON Serializers I've benchmarked my ServiceStack's Json serializer performs the best around 3x faster than JSON.NET. Here are a couple of external benchmarks showing this:

    1. http://daniel.wertheim.se/2011/02/07/json-net-vs-servicestack/
    2. http://theburningmonk.com/2011/08/performance-test-json-serializers/

    ServiceStack (an Open source alternate to WCF) comes pre-configured with .NET's fastest JSV and JSON Text Serializers OOB.

    I see someone include lengthy configuration on how you can bend WCF to configure it to use the slower JSON Serializer shipped with .NET. In Service Stack every web service is automatically available via JSON, XML, SOAP (inc. JSV, CSV, HTML) automatically without any config required, so you get to choose the most appropriate endpoint without any additional effort.

    The same amount of code and configuration for the WCF example in Service Stack is just:

    public class PostMessage
    {
        public string Text { get; set; }
        public List Tags { get; set; }
        public string AspNetSessionId { get; set; }
    }
    
    public class GetUpdatesService : IService
    {
        public object Execute(GetUpdates request){ ... }
    }
    
    public class PostMessageService : IService
    {
        public object Execute(PostMessage request){ ... }
    }
    

    Note: decorating your DTOs with [DataContract] is optional.

    The ServiceStack Hello World example shows all the links different formats, metadata pages XSD Schemas and SOAP WSDLs automatically available after you create a web service.

提交回复
热议问题