Hessian is an even better communication protocol than JSON. Being a binary format it is even more compact, and with a strict format parsing is much faster.
As a bonus there are already frameworks for Java, .NET and PHP to expose a web service. Truly easy. Asume you have this C# interface:
public interface ITest {
public string getGreeting();
int addNumbers(int a, int b);
}
Then implementing it on the server using HessianC# is a snap:
public class CTest:CHessianHandler, ITest {
public string getGreeting() { return "Hello World!"; }
public int addNumbers(int a, int b) { return a + b; }
[STAThread]
private static void Main(string[] args) {
CWebServer web = new CWebServer(5667, "/test/test.hessian", typeof (CTest));
web.Paranoid = true;
web.AcceptClient("[\\d\\s]");
web.Run();
for (;; ) {
if (Console.ReadLine() != "") {
web.Stop();
break;
}
}
}
}
On the iPhone side the C# interface need to be translated into an Objective-C protocol:
@protocol ITest
-(NSString*)getGreeting;
-(int)addNumbers:(int)a :(int)b;
@end
And then using HessianKit for getting a proxy for the service is almost as easy:
id<ITest> proxy = [CWHessianConnection proxyWithURL:serviceURL
protocol:@protocol(ITest)];
NSLog(@"Greeting: %@", [proxy getGreeting]);
NSLog(@"The answer: %d", [proxy addNumbers:40 :2]);
In this short answer the method names are not quite C#-ish, an not quite Obj-C-ish either. This is because by default HessianKit uses Java's naming conventions. This can be overriden in HessianKit by providing method, and type name translations. So that both the C# and the Obj-C sides on the connection feels 100% at home. For example:
[CWHessianArchiver setClassName:@"com.mycompany.ITest"
forProtocol:@protocol(CWTest)];
[CWHessianArchiver setMethodName:@"AddNumbers"
forSelector:@selector(addInt:toInt:)];