下载地址: http://sourceforge.net/projects/hessiankit/
介绍:http://www.jayway.com/2008/07/10/hessiankit-released/
协议介绍 http://hessian.caucho.com/
HessianKit
HessianKit is a Framework for Objective-C 2.0 to allow Mac OS X 10.5, and iPhone 2.0 applications to seamlessly communicate with hessian web services.
HessianKit provided typed proxy objects to formward calls to, and and handle responses from any hessian web service, seamlessly just as if they where local objects. HessianKit also provide functionality to automatically generate classes for published value objects. Both web service proxies and value objects are defined as basic Objective-C Protocols.
Unless the client uses custom value objects, CWHessianConnection is the only class in HessianKit that is needed to be created directly. Instances of CWDistantHessianObject are fetched from CWHessianConnection using proxyWithURL:protocol:. If custom value objects are needed use the CWValueObject to realize objects using protocol definitions, or implement classes conforming to CWNSCoding protocol.
If the web service exposes the following Java-interface:
public interface Service {
int getPersonCount();
Person getPerson(int index);
}
Then the Objective-C client would define the service Protocol as this:
@protocol Service -(int)getPersonCount; -(id<Person>)getPerson:(int)index; @end
Assumin Person is a value object defined as this in Java:
public class Persson implements Serializable {
private int age;
private String name;
public Person(int age, String name) { setAge(age); setName(name); }
public int getAge() { return age; }
public void setAge(int v) { age = v; }
public String getName() { return name; }
public void setName(String v) { name = v; }
}
The Objective-C client would define the same value object as a Protocol like this:
@protocol Person @property(assign, nonatomic) int age; @property(retain, nonatomic) NSString* name; @end
Value object from the web service will automatically be created as a subclas of CWValueObject if the class name matches a defined protocol. Value object to be sent to the web service can be created useing the class method valueObjectWithProtocol: of CWValueObject, or by using any class conforming to NSCoding.
Given the above example the code to get all available persons and write their age and name to logs, could be wimplemented as this:
NSURL* url = [URL URLWithString:@"http:/someserver.org/hessianservice"];
id<Service> proxy = [CWHessianConnection rootProxyWithURL:url protocol:@protocol(Service)];
int count = [proxy getPersonCount];
for (int index = 0; index < count; index++) {
id<Person> person = [proxy getPerson:index];
NSLog(@"age: %d name: %@", person.age, person.name);
}
Since Java and Objective-C differ in the naming of methods, some translation must be done when sending call tho the hessian web service. Method names are first looked up using the class method methodNameForSelector: of CWHessianArchiver, if a method name is not returned, the method name to use will be generated with these steps:
- Split the selector name on ':' delimiter character.
- Capitalize first charcter of all splitted parts but the first.
- Join splitted parts without delimiter.
- If method takes one or more arguments the nme is mangled by appending "__#" where # is the number of arguments.
Some examples of method tranlsations:
Objective-C Java doFoodoFoogetFoo:getFoo__1doFoo:bar:doFooBar__2doUgly:::doUgly__3Many Objective-C constructs feels alien in Java and vice versa, therefor non-automatic method translation can somethimes be prefered, in the above interface
Servicethe method namedpersonis not good looking Objective-C, albeit acceptable Java. To add a manual translation just do:[CWHessianArchiver setMethodName:@"getPersonCount" forSelector:@selector(personcount)]; [CWHessianArchiver setMethodName:@"getPerson" forSelector:@selector(personAtIndex:)];And change the Objective-C Protocol accordingly:
@protocol Service -(int)personCount; -(id<Person>)personAtIndex:(int)index; @end
And now the much more Objective-C friendly code can be written:
NSURL* url = [URL URLWithString:@"http:/someserver.org/hessianservice"]; id<Service> proxy = [CWHessianConnection proxyWithURL:url protocol:@protocol(Service)]; int count = [proxy personCount]; for (int index = 0; index < count; index++) { id<Person> person = [proxy personAtIndex:index]; NSLog(@"age: %d name: %@", person.age, person.name);
HessianKit是一款Objective-C框架,支持Mac OS X 10.5及iPhone 2.0应用无缝对接Hessian Web服务。它提供类型化的代理对象来转发调用并处理来自Hessian Web服务的响应。

被折叠的 条评论
为什么被折叠?



