Go back to the operating environment of the SS
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/57/2F/wKiom1STuCCRipP3AAJMjYAmyzo242.jpg "title=" QQ picture 20141219132858.jpg "alt=" Wkiom1stuccripp3aajmjyamyzo242.jpg "/>
Let's follow the previous article to illustrate the practical classic code in Servicestack.examples (the following code is updated to the new version):
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;&NBSP;&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 }; }
The function implemented by this service is to search for a list of users by a set of IDs or a set of user names. Let's look at the parameter definition of the Ingress class:
public class getusers{public list<long> userids {get; set;} Public list<string> UserNames {get; set;}}
The entry class parameter defines two lists,
UserIDs
A list of user IDs for a set of
Dbconn.getbyids<user> (Request. UserIDs)
Query to a list of users that match this set of IDs, and then call
Users. AddRange
Added to the Data property in the Export class
UserNames
A list of names for the user, by
Dbconn.select<user> ("UserName in ({0})", Request. Usernames.sqlinvalues ())
Query to a group of users that contain this set of user names (in operations through SQL), and then call
Users. AddRange
Added to the data property of the export class
Definition of Export class :
public class getusersresponse{Public getusersresponse () {this.data = new list<user> (); This. ResponseStatus = new ResponseStatus (); Public list<user> data {get; set;} Public ResponseStatus ResponseStatus {get; set;}}
Export class is a set of user entity classes, plus an operation corresponding state class composition, the original Export class user list using the Users property (
This. Users = Arrayofuser{get;set;}
), according to the request to receive ExtJS, the property of this list requires the name of data, here to Data,arrayofuser is a custom collection class used in the old version, we only need to use list<user>, do not need to define this collection
The following is the user entity class:
public class user{[autoincrement] public int Id {get; set;} public string UserName {get; set;} public string Email {get; set;} public string Password {get; set;} Public Guid GlobalId {get; set;}}
The ResponseStatus is an HTTP appropriate state class built into the SS system that encapsulates HTTP error return codes, error messages, and error stacks, and provides three forms of overwrite constructs.
summary: // common responsestatus class that should be present on all response dto ' s [ datacontract] public class responsestatus { // summary: // Initializes a new instance of the servicestack.serviceinterface.servicemodel.responsestatus // class. A response status without an Errorcode == success public responsestatus (); // // Summary: // initializes a new instance of the servicestack.serviceinterface.servicemodel.responsestatus // class. a response status with an errorcode == failure public responsestatus (string ErrorCode); // / / summary: // initializes a new instance of the servicestack.serviceinterface.servicemodel.responsestatus // class. A response status with an errorcode == failure public responsestatUS (string errorcode, string message); // summary: // holds the custom errorcode enum if provided in validationexception otherwise // will hold the name of the exception type, e.g. typeof (Exception). name a value // of non-null means the service encountered an error while processing The request. [datamember (Order = 1)] public string ErrorCode { get; set; } // // summary: // for multiple detailed validation errors. can hold a specific error message // for each named field. [ DataMember (order = 4)] public list< responseerror> errors { get; set; } // // Summary: // A human friendly error message [datamember (order = 2)] public string message&nbsP { get; set; } // [datamember (order = 3)] public string stacktrace { get; set; } }
Updated the project code after using the new Servicestack
http://down.51cto.com/data/1964107
This article is from the "LifeStage" blog, make sure to keep this source http://soaop.blog.51cto.com/6164600/1591988
ServiceStack Project Instance 008 servicestack.examples-2