iOS Development Hessian

Source: Internet
Author: User

Hessiankit use reference less, through groping, the test process, the code is very messy, not organized, first realize the function, and then apply to the project. For novice Reference. If you have any questions ...

The Hessianservice is the same as the Java server-side interface.

Import <UIKit/UIKit.h>

Import "CWHessianArchiver.h"

Import "User.h"

@protocol Hessianservice

-(NSString *) SayHello; To set a non-parameter method, return a string type

-(NSString *) yy: (NSString *) username;//passes a string parameter, returns the string parameter

-(id<user>) gethessianmodel;//, returns an object of type User. In the Java server side there is an entity class that corresponds to the

-(BOOL) Save: (NSString *) userName;

-(Nsarray *) Listall;

-(void) Save2: (NSString *) Username password: (nsstring *) password;

-(int) SYN: (Nsmutablearray *) list;

-(int) Suser: (id<user>) User;

-(int) Slist: (nsmutablearray<user>*) List; Passing the list array

@end

Here is the test method to introduce the relevant header file

Server URL

Nsurl *url = [Nsurl

URLWithString: @http://192.168.1.102:8080/signinservice/mvc/hessian/hessianservice];

Set the proxy class

Id

Protocol: @protocol (Hessianservice)];

The client is associated with a server-side method. You can use a different method name. By Cwhessianarchiver mapping, you can resolve a method not found

[Cwhessianarchiver setmethodname:@ "Yy_1" Forselector: @selector (yy:)];

[Cwhessianarchiver setmethodname:@ "Gethessianmodel" Forselector: @selector (Gethessianmodel)];

[Cwhessianarchiver setmethodname:@ "Save" Forselector: @selector (Save:)];

[Cwhessianarchiver setmethodname:@ "Listall" Forselector: @selector (Listall)];

[Cwhessianarchiver setmethodname:@ "Save2" Forselector: @selector (Save2:password:)];

[Cwhessianarchiver setmethodname:@ "syn" Forselector: @selector (syn:)];

User is associated with the server-side com.listentek.signIn.server.model.User, otherwise the entity class cannot be found. Bring the package name.

[Cwhessianarchiver setclassname:@ "Com.listentek.signIn.server.model.User" Forprotocol: @protocol (User)];

[Cwhessianarchiver setmethodname:@ "Slist" Forselector: @selector (slist:)];

The invocation method is simple,

Calling the SayHello method

NSLog (@ "xxx:%@", [proxy SayHello]);

NSString *re = @ "Hello";

NSLog (@ "web:%@", [proxy yy:re]);

id<user> User = [Proxy Gethessianmodel];

NSLog (@ "name=%@", [User objectforkey:@ "password"]);

Passing individual data

NSLog (@ "save:%@", [proxy save:re]);

Get list data

Nsarray *array = [Proxy listall];

For (ID user2 in array) {

NSLog (@ "name=%@", [user2 objectforkey:@ "password"]);

}

[Proxy save2:@ "hehe" password:@ "yyy"];

Declare entity Class View Cwvalueobject source code, Valueobjectwithprotocol method, for @protocol User initialization, allocate memory.

id<user> u = (id<user>) [Cwvalueobject valueobjectwithprotocol: @protocol (User)];

[u setpassword:@ "xxx"];

[u setusername:@ "yyy"];

NSLog (@ "%@", u);

NSLog (@ "pass=%@,name=%@", u.password,u.username);

[Proxy suser:u];

Passing arrays

Nsmutablearray *array3 = [[Nsmutablearray alloc] init];

[Array3 Addobject:u];

for (int k=1; k<3; k++) {

id<user> U2 = (id<user>) [Cwvalueobject valueobjectwithprotocol: @protocol (User)];

U2.password = [NSString stringwithformat:@ "k%d", K];

U2.username = [NSString stringwithformat:@ "k%d", K];

[Array3 ADDOBJECT:U2];

}

[Proxy slist:array3];

iOS Development Hessian

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.