The first ServiceStack service framework, servicestack framework

Source: Internet
Author: User

The first ServiceStack service framework, servicestack framework

 

The first ServiceStack service framework

Recently, when I first came into contact with ServiceStack, I tried to write the first service framework. It is inevitable that an error will occur. I hope my colleagues can correct me more.

The concepts related to ServiceStack are not described in detail, and there are many great online researchers in this field.

ServiceStack's official website address is:

Https://github.com/ServiceStack/ServiceStack

The main steps are as follows:

1. Create a new Window form program in.

Configure the port in AppConfig of the default program

<? Xml version = "1.0" encoding = "UTF-8"?> <Configuration> <startup> <supportedRuntime version = "v4.0" sku = ". NETFramework, Version = v4.5.2"/> </startup> <etettings> <! -- Port --> <add key = "ServerPort" value = "8001"/> </appSettings> </configuration>

2. Add reference library files related to ServiceStack

3. Add the APPHost. cs file and configure ServiceStack

Public class AppHost: cancelfhostbase {public AppHost (Assembly [] Assemblys): base ("ZBDService", Assemblys) {}// Configure public override void Configure (Container container) {Plugins. add (new CorsFeature (); JsConfig. export denullvalues = true; SetConfig (new HostConfig {DebugMode = true });}}

4. Configure the ServiceStack listener in the Program. cs file in the default Program list.

           static void Main(string[] args)        {            Assembly[] assembly =            {                Assembly.Load("ZBDServiceApp")            };            string port = ConfigurationManager.AppSettings["ServerPort"].ToString();            var listeningOn = args.Length == 0 ? "http://*:" + port + "/" : args[0];            var appHost = new AppHost(assembly)                .Init()                .Start(listeningOn);            Application.EnableVisualStyles();            Application.SetCompatibleTextRenderingDefault(false);            Application.Run(new Form1());        }

5. Create a cs file to store request routes and return value types

// Define a Route for [Route ("/ZBD/Test/{name}", verbs: "GET")] public class ZBD: IReturn <IList <string >>{ public string name {get; set ;}}

6. Create a cs file for specific operations, including database operations.

Public class ZBDServer: Service {public List <string> Get (ZBD request) {List <string> list = new List <string> (); list. add (request. name); list. add ("first service"); return list ;}

7. Run the program, start the service, and test it in the browser.

The above is only the most basic configuration, and you need to learn more.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.