ServiceStack Project Example 007

Source: Internet
Author: User

Servicestack's official website provides a lot of project case download, but some examples can not be used, and the case is also useful for the development of VS2010, SS version is also older, to adjust before you can run.

Official Sample Project Https://github.com/ServiceStack/ServiceStack.Examples/tree/v3

It contains the following sample project (the first directory is an upgrade record to upgrade to VS2013):

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/57/2A/wKiom1STgQqhBZ11AAGuLM0rt1k706.jpg "title=" QQ picture 20141219093523.jpg "alt=" Wkiom1stgqqhbz11aagulm0rt1k706.jpg "/>

There are some project starter templates in the "Startertemplates" catalogue

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/57/28/wKioL1STgnDx6T1IAACuCxg11Ow203.jpg "title=" QQ picture 20141219093802.jpg "alt=" Wkiol1stgndx6t1iaacucxg11ow203.jpg "/>


The SS framework can be used in the VS development environment above. net3.5, which is the minimum requirement VS2008, with a few of the sample projects VS2010, mostly VS2012.


Here is a description of the project "Servicestack.examples",

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/57/28/wKioL1STg32zm_O8AADkwF2_OD4097.jpg "title=" QQ picture 20141219094316.jpg "alt=" Wkiol1stg32zm_o8aadkwf2_od4097.jpg "/>


The program contains 7 projects, three projects in the host directory

ServiceStack.Examples.Clients Web version of the client project

ServiceStack.Examples.Host.Console Console version of the service-side project

ServiceStack.Examples.Host.Web Web version of the service-side project


Two items in the test directory

ServiceStack.Examples.Tests basic function test

ServiceStack.Examples.Tests.Integration Integrated approach testing (client and server integration use)


ServiceStack.Examples.ServiceInterface Services provided by the project (service written on this project)


Items defined by the ServiceStack.Examples.ServiceModel model (with routing included)


This project only needs to publish files in the hosts directory when it is last released, and other projects are basically class libraries and test projects. The invocation of the service in this project uses old-fashioned notation, such as

public class Greetservice:iservice<greet>{public Object Execute (Greet request) {return new Greetresponse {Result = "Hello" + request. Name};}}

The new style of Greetservice:service,execute (Greet request) is proposed in the new style of greetservice:iservice<greet>, which is Get (Greet request). 。 In addition, Servicestack.examples and framework ServiceStack are used in the project. There is conflict, so greetservice:service inheritance can not be written directly, need to write Greetservice:: ServiceStack.ServiceInterface.Service.


Note the definition of the entity Class model in types in ServiceStack.Examples.ServiceModel:

public class CustomerOrders {public CustomerOrders ()} {this.        Orders = new list<order> ();        Public customer customer {get; set;} Public list<order> Orders {get; set;}

The CustomerOrders table contains data for the foreign Key Association of the customer and Orders two tables, However, in the 3.x example, there is no foreign key association to get the data of the associated table, but rather by setting the associated inner class in the entity class, when fetching the data in the service, the multi-table data is implemented, which is a consistent implementation of the methods and ideas used by NoSQL.

(In this example, there is no demonstration of the combined merge process when fetching multi-table data, but rather a set of sample data, which is already set up in the sample data, and the data obtained for CustomerOrders is customer plus a list of order, After the combination of the direct return to the service, see the "ServiceStack.Examples.ServiceInterface" project under the Getnorthwindcustomerordersservice)


It is worth highlighting and explaining the service implementation of the GetUsersService.cs file in the ServiceStack.Examples.ServiceInterface project to obtain a list of users based on a set of IDs or usernames:


Program code: (After repair)

     public object any (getusers request)          {            using  (Var  dbconn = connectionfactory.opendbconnection ())              {                 var users = new List<User> ();                 if  (Request. Userids != null && request. userids.count > 0)                  {                     users. AddRange (dbconn.getbyids<user>) (Request. UserIDs)); &NBSP;&NBSP;&NBSP;&NBsp;            }                 if  (Request. Usernames != null && request. usernames.count > 0)                  {                     users. AddRange (dbconn.select<user> (                          "username in  ({0})",  Request. Usernames.sqlinvalues ()));                 }                 Return new getusersresponse { data = users };            }         }











ServiceStack Project Example 007

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.