Ad

Our DNA is written in Swift
Jump

Kernseife (SOAP for iPhone)

Applyzer.com has a SOAP-based API, which is also how AppViz is getting the ranking data. I’ve been putting it off for a while, but finally I tried to find a painless way to generate proxy classes for the webservice. I failed.

Well, not entirely, there IS a plethora of frameworks and toolkits that promise to automatically generate proxy classes for you. Only problem, these are either C++ based, or use libxml or use other xml parsers like are present in CoreFoundation on the Mac, but not on the iPhone. Also the code that gets generated by tools like wsdl2objc gives me the creeps.

A proxy class is a class that looks like a normal class that you can instantiate and use it’s methods. But behind the scenes it packages all calls in SOAP or HTTP GET/POST, calls the server, retrieves the answer and unpackages the returning SOAP envelope. Basically you program against the web service as if the functionality offered is part of your local code.

reine KernseifeSo I started the “Kernseife” project. Originally I was tempted to call it SOUCH, like SOAP Touch, but I found this term to by synonymous with the pain of being kicked in the family jewels. Second idea was to call it CoreSOAP because it’s something that I would have expected for Apple to provide. But then I figured, how about the German translation? Core means “Kern” and Soap means “Seife” and the Soap product called “Kernseife” is synonymous with a very healthy and very thorough cleansing. Just what I had in mind for this project.

Don’t tell me now that “SOAP is dead” and now everything is JSON, XML+RPC or REST. Most of the web service world around Microsoft, IBM, SUN and Java knows how to speak SOAP and since it’s the standard transport for the .NET framework based web services I run, there will be no discussion regarding SOAP’s viability. It’s there, I am going to talk with it.

So far the project is able to generate proxy classes for very simple web methods:

  • A single return value per method
  • No complex types
  • only string, int, double, dateTime
  • Supported transports are SOAP 1.0, 1.2, HTTP POST and HTTP GET
  • No error handling
  • No SOAP exception handling

Because there is still lot of work necessary to make it complete I chose to make it Open Source and created a project on Google Code. I will continue to update and improve the code as I need for my ongoing projects and I am happy to share development with anybody who has some ideas on how to do stuff even smarter. Specifically the next improvements I am looking for are:

  • Add SOAP exception handling, possibly using NSError or objC exceptions
  • Add complex data types by autogenerating classes or structs for them
  • Add the conversions for the missing simple datatypes in the XML schema
  • Unit Testing against a variety of WSDL files
  • Documentation and Samples

To get the code into your hands you can check out a working copy via Google’s instructions. If you’re interested in contributing then contact me so that I can make you a project member.

When you have downloaded and built the code you get a Mac binary called Kernseife which has one parameter: a file path or URL.

$ ./Kernseife http://www.drobnik.com/services/testservice.asmx?wsdl

This analyzes the WSDL file and outputs a the .h/.m files for a proxy class:

These ports where found:
- TestServiceSoap
- TestServiceSoap12
- TestServiceHttpGet
- TestServiceHttpPost
 
Writing class files for first port
Done.

Have a look at the header to check if all the input and output parameters could be generated:

// TestService.h
 
#import
#import "WebService.h"
 
#import "NSString+Helpers.h"
#import "NSDate+xml.h"
 
@interface TestService : WebService
{
}
 
- (NSString *) helloWorld;
- (NSDate *) dateInWithInDate:(NSDate *)inDate;
- (NSDate *) jetzt;
- (double) addWithOne:(double)one two:(NSInteger)two;
 
@end

Add these files to your project and also add all the files in the “xml” group of the Kernseife project.

Kernseife Files

Then you should be ready to test the proxy class.

// #import "TestService.h"
 
TestService *service = [[[TestService alloc] init] autorelease];
 
NSDate *nun = [service jetzt];
NSLog(@"Time now from service: %@", nun);
 
NSDate *dann = [service dateInWithInDate:nun];
NSLog(@"Pass-Through Time: %@", dann);
 
double ret = [service addWithOne:1.5 two:2];
 
NSLog(@"Added double and int: %f", ret);

From the initial feedback I have gotten for the basic premise of Kernseife I can tell that there is a tremendous need for such a project. So I appreciate your feedback and/or help going forward.


Categories: Projects

0 COmments »

  1. Wish this had been around when we were doing the transport code for MyMobileGolf … that was a real pain.

    Currently we’re implementing a server proxy to convert the SOAP XML into a reduced set of JSON results in order to speed up download and (especially) processing time/memory.

    However, if another project comes along that requires SOAP I’ll definitely be checking the progress on this project.

  2. It would be great if you could contact me when you get to needing to access a new SOAP service so that I can check if all works there.