(original) Multi-system needs docking, I wrote an interface framework. Practicality is very strong, write to everyone to communicate. Need to be able to move directly past use. (1th article)

Source: Internet
Author: User

The business is this: a mobile app, developed on iOS or Android, needs to access server data. I do an interface on the server, specifically to open up some data to the app to use.

I write the interface advantages: I write this interface, all is object-oriented structure, the code is simple and very useful, very easy to expand. Very readable and highly tolerant.

Personal advice to students who need it can be used directly to the project. I'll talk about his way of making one step at a pace.

1th step, create a project, create a site in the project, and a business operations class library. Such as:

is the website.


is a class library

The 2nd step is to create several root class. cs files.

For example, create:
Post.cs files: For receiving post requests
Get.cs file: Used to receive a GET request
Factory.cs file: Module factory. For example, your mobile app has a news module, a voice module, and a variety of modules. All modules get instance objects from this factory.
Code.cs file: Return to the caller, some agreed prompt code and information.
BaseCommand.cs file: base class for requests. This base class is inherited by both a post and a GET request.

3rd step. Write the code for the underlying file. A map of a file is elaborate.
First come: BaseCommand.cs file:


usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Web.Script.Serialization;usingZgmz.common;namespaceZgmz. UIL. app{/// <summary>    ///base class/// </summary>     Public Abstract classBasecommand {InternalBasecommand () {}/// <summary>        ///Message Results/// </summary>        InternalCode Code {Get;Set; } /// <summary>        ///returned message detail description/// </summary>        protected stringerrormessage {Get;Set; } /// <summary>        ///the object to be serialized/// </summary>        protected ObjectOutobject {Get;Set; } /// <summary>        ///Output Parameters/// </summary>         Public stringOutput {Get            {                stringresult ="\"\""; if( This. Outobject! =NULL) {result= This. Serialize ( This.                Outobject); }                //Output Results                stringOutput ="{\ "codeid\": \ ""+ This. Code.codeid +"\ ", \" codedescription\ ": \""+ This. Code.description +"\ ", \" errormessage\ ": \""+ Htmlhelper.removequotes ( This. ErrorMessage) +"\ ", \" result\ ":"+ result +"}"; returnoutput; }        }        /// <summary>        ///Serialization of/// </summary>        /// <param name= "Queryparameters" ></param>        /// <returns></returns>        Private stringSerialize (Objecto) {javascriptserializer JSS=NewJavaScriptSerializer (); stringdata =JSS.            Serialize (o); returndata; }        /// <summary>        ///Perform Actions/// </summary>         Public Abstract voidExcute (); }}

Code Commentary:
This is an abstract base class.
Code code {get; set;} is a property accessor that returns a message code. When the interface is invoked, the message code is returned to each other, whether successful or not.


String ErrorMessage {get; set;} Is the description of the message code: For example, the message code is 100. His correspondence is "success".


Object Outobject {get; set;} When someone calls the interface, it returns a result to the other person. Before returning the result, we need to store the object first. Because we don't know what type of thing to return to the caller, so we use object as the type. Save the object you want to return first.


String output{get; set;} Output Result: We are saving an object of type Outobject, and it is not possible to return this object directly to the caller. Because the caller, it is generally required to get the JSON format, or get the XML format: The effect of this output is to convert the object value to a string-type JSON string or an XML string, which is output to the caller.


String Serialize (Object o) serialization. The object is outobject by this serialized method, which can become a string of type JSON string. Finally, the output property is used and can be exported to the caller.


abstract void Excute () This is an abstracted method. For example, when an app requests a server, it must implement a function. This excute is the implementation of this business logic.

When you want to see this, there are 4 more: Here are the links:

(original) Object-oriented system docking interface programming. 2nd article http://www.cnblogs.com/mazhiyuan/p/5224049.html

(original) Object-oriented system docking interface programming. 3rd article http://www.cnblogs.com/mazhiyuan/p/5224050.html

(original) Object-oriented system docking interface programming. 4th article http://www.cnblogs.com/mazhiyuan/p/5224054.html

(original) Object-oriented system docking interface programming. 5th (end) http://www.cnblogs.com/mazhiyuan/p/5224056.html

If read, have not understood can comment to me.

It's really good to use. There are students who need to do the interface. The entire frame can be used.

(original) Multi-system needs docking, I wrote an interface framework. Practicality is very strong, write to everyone to communicate. Need to be able to move directly past use. (1th article)

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.