which one best for iphone application ? JSON is different from these three webservice methods ?
could you please suggest me..
which one best for iphone application ? JSON is different from these three webservice methods ?
could you please suggest me..
JSON is just a serialization format, whereas SOAP and XML-RPC are more like request-response exchange protocols. This basically allows you to invoke remote methods.
In other words, you cannot really compare these. If you're building RESTful applications, serialization to JSON (or plain old XML, for that matter) should be just fine. And please for all good there is in the world (this is subjective, inflammatory and argumentative) do not use either SOAP or WS-* unless it's absolutely neccessary.
Agreeing with Anton, JSON is a serialization format (like XML or CSV). JSON is typically lighter weight than XML, but there are some data structures that don't lend themselves to JSON serialization.
If you're using a RESTful interface you can, but not recommended, alternate between JSON and XML depending upon the service call. I've found using XML for the serialization method to fit nicely into the iPhone SDK since it provides native XML stream parsing in NSXMLParser.
JSON could be one of the formats a REST request gets its answer into.
JSON, being directly parsable in a browser environment, is the best format to communicate in a web application heavily interactive. REST is a way to define a clever GET or POST request to a server than can reply in various formats: xml, plain text, json.
For a web app or an iPhone app, I'd go with it.
It needs the less libraries (or none at all) goes well with async http requests, has the smallest overhead and doesn't go great lengths like SOAP and XML-RPC resolving problems web apps usually DO NOT have: strong typing, mainly.
Hessian is much better communication protocol than XML and/or JSON. Being a binary format it is even more compact, and with a strict format parsing is much faster. And it also consumes much less memory. As a bonus a simpler parser also means your application is more secure.
As a bonus there are already frameworks for Java, .NET and PHP to expose a web service. Truly easy. Asume you have this Java interface:
public interface Test {
public String getGreeting();
int addNumbers(int a, int b);
}
Then implementing it on the server using Hessian is a snap:
public class TestSevlet extends HessianServlet implements Test {
public String getGreeting() { return "Hello World!"; }
public int addNumbers(int a, int b) { return a + b; }
}
The server can also with just as easily be implemented in .NET or PHP for example. There are numerous of Hessian implementations available.
On the iPhone side the Java interface need to be translated into an Objective-C protocol:
@protocol Test
-(NSString*)getGreeting;
-(int)addNumbers:(int)a :(int)b;
@end
And then using [HessianKit][2] for getting a proxy for the service is almost as easy:
id<Test> proxy = [CWHessianConnection proxyWithURL:serviceURL
protocol:@protocol(Test)];
NSLog(@"Greeting: %@", [proxy getGreeting]);
NSLog(@"The answer: %d", [proxy addNumbers:40 :2]);
In this short answer the method names are not quite Obj-C-ish. 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 Java and the Obj-C sides on the connection feels 100% at home. For example:
[CWHessianArchiver setClassName:@"com.mycompany.Test"
forProtocol:@protocol(CWTest)];
[CWHessianArchiver setMethodName:@"AddNumbers"
forSelector:@selector(addInt:toInt:)];