This article is a mirror article of machine translation, please click here to jump to the original article.

View: 24900|Reply: 4

[WebAPI] My first ServiceStack Web Service application build

[Copy link]
Posted on 1/15/2018 11:06:52 AM | | | |
I want to try the difference between ServiceStack Web and Microsoft's built-in webapi, and see what advantages there are, so try to build a ServiceStack Web Service application today

1: Create a new .NET 4.5 web empty project, and then use the nuget command to install ServiceStack:

.net version must be greater than or equal to version 4.5, the 4.0 project will not be installed successfully! As shown in the figure below.



2: Create a new model and service folder

Create a request and response entity with the following code:

3: Create a service interface in the service folder

4: Create a new global application class named Global.asax to this project, and the code is as follows:




5: Modify the web.config configuration, add a new system.webServer node, and the complete configuration is as follows:



So far our service has been completed, running the program can see the interface as follows,GetAllUserInfoRequest and GetByAgeUserInfoRequest can be understood as actual call methodsThe parameters defined in it can be interpreted as the request parameters of the method, as shown in the figure below:



The service methods in ServiceStack are named Any, Get, and Post, which are also supported request types by ServiceStack.Any means that the service can be called in both HTTP Get and HTTP Post。 This strengthens and simplifies the implementation of RESTFull-style WebServices. Just add love [Route(...)] on these methods Attributes. In ServiceStack,The difference between methods and methods is distinguished by the parameters of the service and the request object Request DTO, rather than differentiating by method name as in WCF. This meansA request DTO object cannot be reused across multiple Services in ServiceStack

Adding the format parameter after the get request parameter can return the type of response, such as: format=json, format=xml, etc., and it seems that the jsonp format is also supported.

For example: http://localhost:52079//json/reply/GetAllUserInfoRequest?format=xml



To sum up, compared with Microsoft's web API, ServiceStack seems to have no concept of method in the web, it is a different request entity is a method, it can automatically generate interface documents, and the format of the response can be returned through format (although Microsoft's is also possible, but it feels simpler than Microsoft)

Reference: https://www.cnblogs.com/woxpp/p/5012947.html

https://msdn.microsoft.com/zh-cn/magazine/dn342871.aspx

https://github.com/ServiceStack/ServiceStack/wiki

Finally, attach the project source code!

Tourists, if you want to see the hidden content of this post, pleaseReply





Previous:System.NotImplementedException:“未实现该方法或操作。”
Next:Visual Studio adds the powerful editing capabilities of Vim to make it difficult to prevent!
Posted on 3/6/2018 3:28:29 PM |
Look, how is it?
Posted on 4/14/2019 8:08:39 PM |

Look, how is it?
Posted on 8/8/2019 8:29:02 AM |
ServiceStack Web Service
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com