Briefely, you use this framework in four steps:
You do this typically by passing the URL of the WebService to the init constructor, specifying the JSON-RPC version supported by the WebService:
JSONRPCService* service = [[JSONRPCService alloc] initWithURL:kServiceURL version:JSONRPCVersion_1_0];
To do this, you have multiple equivalent possibilities:
Use the callMethodWithName:parameters: (JSONRPCService) or callMethodWithName:namedParameters: (JSONRPCService) method, passing it the name of the method to call (an NSString) and its parameters (an NSArray for the first case, NSDictionary for the second)
Use the callMethodWithNameAndParams: (JSONRPCService) or callMethodWithNameAndNamedParams: (JSONRPCService) method, passing it the name (NSString) of the method to call, followed by a variable number of arguments representing the parameters, terminated by 'nil'.
This variable number of arguments are at the same format as:
Create a JSONRPCMethodCall object, passing it the name of the method to call and its arguments, then pass it to the callMethod: (JSONRPCService) to actually call the method. (This is actually what the two previous options do in their implementation).
Ask the JSONRPCService for a proxy object (see JSONRPCService::proxy), then call directly any method you want as an Objective-C call (as if it was the WebService itself), with the arguments in an NSArray or NSDictionary. The following 3 lines will in fact be equivalent:
[service.proxy echo:[NSArray arrayWithObject:@"Hello there"]] [service callMethodWithName:@"echo" parameters:[NSArray arrayWithObject:@"Hello there"]]; [service callMethodWithNameAndParams:@"echo",@"Hello there",nil];
When you call a JSON-RPC method, you get a JSONRPCResponseHandler object as a return value.
JSONRPCResponseHandler* h = [service callMethodWithName:@"echo" parameters:mkArray(@"Hello there")]; // (1) If we stop here, the response will be received by the JSONRPCService's delegate method methodCall:didReturn:error: [h setDelegate:x]; // at this stage, the response will be received by x through the method methodCall:didReturn:error: [h setCallback:@selector(remoteProcedureCall:didReturnObject:serviceError:)]; // at this stage, the response will be received by x through the method remoteProcedureCall:didReturnObject:serviceError:
Note that you can nest the JSONRPCService method call with the JSONRPCResponseHandler calls to be more concise:
[[service callMethodWithNameAndParams:@"echo",@"Hello there",nil] setDelegate:self callback:@selector(methodCall:didReturn:error) resultClass:[MyCustomClass class]];
Of course don't forget to release your JSONRPCService when you are done.
As you can see, the usage of this framework is highly flexible. You can call a JSON-RPC method using multiple different syntaxes, and you can also receive the response in the way you think it's the best suitable for your project, centralizing the responses on one object (the JSONRPCService::delegate) or on separate objects (JSONRPCResponseHandler::delegate) and calling a unique @selector method for handling the response of all your method calls, or a different @selector for each.
For more information, you can look at the Example.