Web Service Integration, Mac vs. PC
As Ben mentioned in the first installment (I am a guest blogger for this installment), part of the original decision to build Phanfare on Microsoftâs .NET platform was the ease with which Visual Studio lets you build web services and clients that integrate with those services.
Building a .NET web service method within Visual Studio isnât really much different than writing any other function. You make it a web method by simply adding the â[WebMethod]â? attribute. Visual Studio takes care of everything else under-the-hood. For example, here is the C# web service definition of an imaginary method:
[WebMethod]
public PhanfareAlbum GetAlbum(string sessionId, long albumId, bool getImagesToo, out int albumVersion, out string albumName, out PhanfareImage[] images)
{
â¦
}
Easy, huh?
Using that web method in another application (like the Phanfare Photo client) is also simple. By referencing the web service in the client applicationâs Visual Studio project, Visual Studio will fetch the serviceâs WSDL document (Web Services Definition Language — an XML document that describes the methods that the service provides) and generates a proxy class that contains the stub methods — methods that look just like the ones you wrote on the service side. This generated code handles all the icky details of performing the under-the-hood magic to invoke the method on another machine across the network, while making it look like a local method call to you, the programmer.
The web method declared above is invoked from a C# client application like this:
PhanfareWebService ws = new PhanfareWebService();
string albumName;
int albumVersion;
PhanfareImage[] images;
// See how nice? The client call looks just like a local call to the web method.
PhanfareAlbum myAlbum = ws.GetAlbum(mySessionId, 12345, iWantTheDarnImages, out albumVersion, out albumName, out images);
// Now use the info!
Debug.WriteLine(String.Format(âThis album was created on {0}â?, myAlbum.createdDate.ToString()));
Facile!
Now for the Mac side of the story.
To make the Phanfare Photo Mac client work, it would have to talk to the same SOAP web service as the Windows client. When we first began looking at the Mac platform, we were excited to have read somewhere that OS X supports SOAP-based web services. However our excitement quickly dissipated when, in typical Apple style, we couldnât find any coherent, useful documentation on how to integrate a Cocoa application with a SOAP-based web service (if you find some, please let us know. Here is Appleâs documentation. Now go build a complex web service client on the Mac. Have fun.). From what I could gather you put all of your parameters (no complex user-defined types, please) into a hash table (so if I get the parameters wrong I can still compile my client with no errors? Wonderful.), pass it to some web service invocation function, and then get a hash table back. Oh and if you run Appleâs WSMakeStubs application on Phanfareâs WSDL you basically get a lot of methods that have nothing but comments stating that complex types are not supported. Great.
After quickly realizing that Appleâs limited support for web services wasnât going to make our lives any easier, we started looking for alternatives (to be honest Appleâs support seemed so lacking that we never even tried to build a test application before looking elsewhere). What we found was gSOAP, by Robert van Engelen at Florida State University. We decided to use gSOAP for several reasons: it is open source and distributed under the very favorable gSOAP License, it is extremely well documented, it is widely used, and it has an extremely active user community. Oh, and it works on the Mac (it even came with a Mac-specific makefile).
The primary complaint we had with gSOAP was that it did not integrate seamlessly with Objective-C/Cocoa, the environment in which weâd chosen to develop the Mac client. While gSOAP worked quite well in our tests, calling it from Objective-C/Cocoa looked something like this:
struct soap *mySoap = soap_new2(SOAP_IO_DEFAULT, SOAP_IO_DEFAULT);
// gSOAP takes input and provides output parameters via structs,
// not return values and in/out parameters the way the
// Visual Studio-genarated stub methods do.
struct _ns1__GetAlbum inParameters;
// Weâre using NSStrings in our code. gSOAP needs a char *, so I need to convert.
inParameters.session_id = [mySessionId UTF8String];
inParameters.albumId = 12345;
// Weâre using Objective-C booleans in our code, need to convert to the
// gSOAP-defined true_ and false_ enumeration values.
inParameters.getImagesToo = iWantTheDarnImages == YES ? true_ : false_;
struct _ns1__GetAlbumResponse soapOutParameters;
int soapRv = soap_call__ns1__GetAlbum(soap, endpoint, NULL, &soapInParameters, &soapOutParameters);
// Now use the info! But wait! I must convert the time_t to an NSDate first!
NSLog([NSString stringWithFormat:@â?This album was created on %sâ?, [[NSDate dateWithTimeIntervalSince1970:soapOutParameters->albumDate] description]]);
// Now, all my return parameters
// (the PhanfareAlbum, albumName, albumVersion, and the array of images)
// are in âsoapOutParametersâ? and are C types.
// But I want NSStrings, NSDates, NSArrays, Objective-C Booleans…
// not char *âs, time_tâs and C arrays!
// I want Objective-C objects, not C structs!
// So, I guess I have to convert them. For example…
NSString albumName = [[NSString stringWithCString:soapOutParameters->albumName] retain];
int albumVersion = soapOutParameters->albumVesrion;
Clearly this will become very tedious very quickly and is not conducive to rapidly developing an application (especially on a platform thatâs new to you and especially when you make lots of web service calls, like we do). What we needed was a way to make the web service calls look like the calls we were used to, but using Objective-C/Cocoa types.
To achieve this, we modified the gSOAP compiler (the thing that generates the web service stub methods from the WSDL — the same thing Visual Studio does when you add a web service reference to your project) to emit Objective-C in addition the code it already generates. This new code includes Objective-C class equivalents for all user-defined classes, using Cocoa/Objective-C types where appropriate (e.g., for member strings, arrays, booleans, dates, and other user-defined classes). It also contains an automatically generated Objective-C proxy class that implements Objective-C methods that look just like the original web service methods weâve come to know and love, but using Objective-C/Cocoa types. These methods contain all the yucky glue (like in the example above) needed to convert between the C and Objective-C/Cocoa types (again, for strings, dates, arrays, binary data and such).
Now the web service call from Objective-C looks like this:
// PhanfareWebService is the Objective-C âproxyâ? class
PhanfareWebService *ws = [PhanfareWebService init];
int albumVersion;
NSString *albumName;
NSArray *images;
// See how nice this is now? Everything returned to me is an Objective-C/Coca type.
PhanfareAlbum *myAlbum = [ws GetAlbum:sessionId albumId:12345 getImagesToo:getTheDarnImages outabumVersion:&albumVersion outalbumName:&albumName outimages:&images];
// Now use the info!
NSLog([NSString stringWithFormat:@â?This album was created on %sâ?, [[myAlbum createdDate] description]]);
Much nicer, huh?
In addition the proxy layer does a few other nice things, like cleaning up some minor rough edges in gSOAP (e.g., beautifying enumeration types and values and such) and providing support for pooling multiple gSOAP contexts to simplify multithreading.
So, after initial excitement, then disappointment in Appleâs support for SOAP web services, gSOAP, with the addition of our own Objective-C/Cocoa layer, has turned out to be a very nice alternative. It has caused us very few headaches (and most of those were from bugs in our own generated code) and is now as easy to code against as Visual Studio generated stubs on the Windows side. Granted, we donât have the right-click-and-choose-Update-Web-Reference level of integration and ease that Visual Studio provides. But weâve come darn close.
Will you publish those changes you made to gSOAP or roll them into gSOAP baseline?
Duane
December 10, 2006 at 8:46 pm
I second Duane’s comment; *please* consider releasing your additions to gSOAP. I know that I would greatly appreciate it. Thanks.
Josh
May 22, 2007 at 12:22 pm
I third the above! Would be great if you guys could release this 🙂
cal
August 14, 2007 at 1:22 am
At the risk of sounding repetitive, I would fourth the above. I think you would be doing a great service to the community, since Apple’s support for web services is sorely lacking at the moment.
David Mullaney
August 22, 2007 at 5:18 am
I’ll love to see your modifications in gSOAP as well. Even publishing some diff’s would be great.
Jim Turner
August 31, 2007 at 5:52 pm
I fifth the above… it would be extremely nice of you to publish your modifications, even if lacking documentation.
DL
February 10, 2008 at 8:35 pm
Are you still using gSOAP for your applications? Like the others, I would love to see the changes,
Eric
August 16, 2008 at 12:31 am
I 6th the above – please contribute to gSOAP community by at least submiting your documented changes to the gSOAP admin.
Cristi
August 19, 2008 at 1:30 pm
I am very interested in seeing Objective-C support added to gSoap. Would you be interested in contributing the work you mention in this blog entry to an open-source initiative to bring gSoap to the Objective-C/Cocoa world? I would be happy to setup/sponsor such an open-source initiative.
Please e-mail me back if this is something you would be interested in doing. Based on the other comments attached to this blog post, I think there is a need for this support.
Many thanks
Bennett Smith
October 5, 2008 at 7:24 pm
I would add my support to those asking you to release the changes you made to gSOAP.
Lawrence Johnston
November 13, 2008 at 3:21 pm
This is the second blog I have come through about Mac Vs. PC. I was thinking of turning my PC into a MAC but really have no idea whether it’ll work well for me or not. Which one do you suggest to use for personal purpose only? I mean- I am not very much into professionalism in this field.
Marius
September 14, 2009 at 9:04 am
I think a few pictures might help this blogThanksmark______________________________________________Cheap Aion kinah | aion kinha
morgage31
October 10, 2009 at 1:49 am
I think a few pictures might help this blogThanksfreanch______________________________________________aion gold | aion kinha
morgage31
October 15, 2009 at 2:23 am
Please release the new edition…
used cars in bangalore
October 17, 2009 at 3:25 pm
Excellent! Great article, I already saved it to my favourite,
service_call_software
October 18, 2009 at 1:52 pm
where do i get more information on thisregardsmike jumper______________________________________________
CZ Ring
November 17, 2009 at 2:32 am
Nice and useful information about Web Service Integration, Mac vs. PC. Thanks for share nice information.
SEO India
November 20, 2009 at 6:53 am
Don't listen to mean people. You are awesome and you have a huge heart. RespectJoy______________________________________________
breast augmentation prices
November 24, 2009 at 11:24 pm
Man, you are on fire today. Great postsHave a nice dayJustin Kemp______________________________________________
Computer Repair Baltimore
November 24, 2009 at 11:42 pm
I like the part where you say you are doing this to give back but I would assume by all the comments that this is working for you as well.regardsswich______________________________________________debt management programs
millipo31
December 24, 2009 at 7:15 am
In ffice right now will go through this latter.Have a nice dayjaine______________________________________________Mortgage rates
macjui89
December 24, 2009 at 7:15 am
I want to express my admiration of your writing skill and ability to make reader to read the while thing to the endThanksWilson mark______________________________________________
North Carolina Furniture
December 29, 2009 at 7:31 am
I subscribed to your blog when is the next postregardsspoach______________________________________________cosmetic dentist philadelphia | cosmetic dentist philadelphia | dentists in philadelphia | dentists philadelphia | dentists philadelphia | cosmetic dentist philadelphia | cosmetic dentist philadelphia | cosmetic dentists philadelphia | dentists philadelphia | dentists in philadelphia | dentists in philadelphia | dentists philadelphia | cosmetic dentist philadelphia | cosmetic dentists philadelphia | dentists philadelphia | dentists philadelphia | dentists philadelphia | cosmetic dentists philadelphia | dentists in philadelphia | dentists philadelphia | cosmetic dentists philadelphia | cosmetic dentist philadelphia | cosmetic dentists philadelphia | dentists philadelphia | dentists in philadelphia | cosmetic dentists philadelphia | dentists in philadelphia | dentists philadelphia | cosmetic dentists philadelphia | dentists in philadelphia | cosmetic dentist philadelphia | dentists philadelphia | dentists philadelphia | dentists in philadelphia | cosmetic dentists philadelphia | cosmetic dentists philadelphia | cosmetic dentist philadelphia | cosmetic dentists philadelphia | cosmetic dentist philadelphia | cosmetic dentist philadelphia | cosmetic dentist philadelphia | dentists philadelphia | cosmetic dentist philadelphia | dentists in philadelphia | cosmetic dentists philadelphia | dentists philadelphia | cosmetic dentists philadelphia | cosmetic dentist philadelphia | dentists in philadelphia | cosmetic dentist philadelphia | dentists in philadelphia | dentists in philadelphia | dentists in philadelphia | dentists in philadelphia | cosmetic dentist philadelphia | dentists in philadelphia | dentists in philadelphia | cosmetic dentist philadelphia | cosmetic dentists philadelphia | cosmetic dentist philadelphia | cosmetic dentist philadelphia | dentists in philadelphia | cosmetic dentist philadelphia | dentists in philadelphia | dentists in philadelphia | dentists in philadelphia | cosmetic dentist philadelphia
millipo30
January 8, 2010 at 5:44 am
This is a cool screen idea ! It is very interesting indeed.Thank you for your info.i love to read all info.regardsspoach______________________________________________Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris | Haris
millipo10
January 12, 2010 at 6:37 am
Well this is very interesting indeed.Would love to read a little more of this. Great post. Respectspoach______________________________________________Lo | Jk | Jk | Jk | Jk | Jk | Mp | Sf | Jk | Sf | Jk | Sf | Jk | Mp | Lo | Lo | Lo | Lo | Jk | Sf | Sf | Jk | Mp | Sf | Jk | Sf | Jk | Lo | Mp | Jk | Sf | Sf | Jk | Jk | Jk | Lo | Sf | Lo | Mp | Lo | Sf | Mp | Jk | Jk | Jk | Sf | Mp | Sf | Sf | Mp | Sf | Jk | Jk | Lo | Lo | Mp | Lo | Lo | Jk | Sf | Lo | Mp | Mp | Jk | Sf | Sf | Jk | Lo | Mp | Sf | Jk | Lo | Jk | Mp | Sf | Lo | Lo | Lo | Sf | Sf | Jk | Lo | Jk | Mp | Jk | Sf | Jk | Lo | Jk | Lo | Mp | Jk | Sf | Sf | Jk | Jk | Sf | Mp | Mp | Lo | Sf | Jk | Sf | Jk | Sf | Mp | Jk | Sf | Mp | Lo | Jk | Sf | Mp | Lo | Jk | Sf | Jk | Mp | Jk | Jk | Lo | Mp | Sf | Mp | Sf | Jk | Mp | Sf | Sf | Sf | Lo | Sf | Sf | Sf | Lo | Mp | Jk | Mp | Lo | Sf | Sf | Sf | Lo | Lo | Lo | Jk | Lo | Mp | Lo | Lo | Sf | Jk | Mp | Sf | Mp | Sf | Lo | Lo | Lo | Sf | Mp | Sf | Lo | Lo | Sf | Sf | Sf | Sf | Sf | Sf | Jk | Lo | Lo | Jk | Jk | Mp | Jk | Mp | Jk | Mp | Sf | Sf | Jk | Lo | Jk | Sf | Mp | Sf | Jk | Mp | Sf | Sf | Jk | Jk | Sf | Lo | Lo | Lo | Jk | Sf | Jk | Jk | Mp | Jk | Mp | Lo | Mp | Mp | Sf | Sf | Sf | Mp | Lo | Mp | Lo | Jk | Mp | Jk | Mp | Jk | Lo | Mp | Lo | Lo | Jk | Jk | Jk | Sf | Mp | Mp | Jk | Sf | Jk | Mp | Lo | Sf | Mp | Jk | Sf | Sf | Jk | Sf | Mp | Sf | Lo | Lo | Jk | Lo | Mp | Jk | Jk | Mp | Jk | Sf | Lo | Sf | Mp | Sf | Mp | Mp | Mp
millipo22
January 19, 2010 at 5:23 am
your post too nice.respecttomson gerry______________________________________________
moving to asheville, nc
January 23, 2010 at 12:53 am
Well this is very interesting indeed.Would love to read a little more of this. Great post. thanksjoy______________________________________________Sf | Lo | Lo | Sf | Lo | Jk | Sf | Lo | Jk | Jk | Lo | Sf | Sf | Jk | Mp | Jk | Sf | Sf | Lo | Sf | Lo | Lo | Mp | Sf | Lo | Lo | Lo | Jk | Lo | Sf | Mp | Sf | Sf | Lo | Jk | Mp | Lo | Mp | Mp | Lo | Sf | Mp | Jk | Sf | Sf | Lo | Mp | Lo | Sf | Sf | Sf | Mp | Lo | Sf | Lo | Jk | Sf | Jk | Jk | Jk | Lo | Mp | Mp | Mp | Lo | Sf | Mp | Sf | Mp | Jk | Jk | Lo | Sf | Mp | Sf | Sf | Lo | Lo | Mp | Sf | Mp | Lo | Sf | Jk | Jk | Sf | Sf | Lo | Sf | Sf | Mp | Sf | Lo | Mp | Mp | Lo | Jk | Sf | Sf | Lo | Jk | Sf | Mp | Sf | Mp | Jk | Jk | Sf | Lo | Sf | Lo | Mp | Mp | Sf | Sf | Sf | Jk | Jk | Sf | Jk | Mp | Mp | Jk | Sf | Jk | Mp | Sf | Mp | Jk | Sf | Sf | Mp | Jk | Sf | Mp | Sf | Lo | Sf | Sf | Sf | Jk | Lo | Sf | Sf | Jk | Mp | Sf | Sf | Lo | Jk | Jk | Mp | Sf | Mp | Lo | Jk | Sf | Jk | Mp | Mp | Mp | Jk | Jk | Lo | Sf | Mp | Jk | Mp | Sf | Mp | Mp | Sf | Jk | Jk | Sf | Sf | Jk | Mp | Mp | Jk | Jk | Sf | Jk | Lo | Jk | Jk | Jk | Mp | Mp | Mp | Jk | Sf | Lo | Jk | Sf | Jk | Lo | Jk | Sf | Jk | Sf | Mp | Jk | Mp | Sf | Mp | Mp | Jk | Sf | Mp | Jk | Lo | Mp | Mp | Lo | Lo | Jk | Lo | Lo | Lo | Lo | Mp | Sf | Sf | Lo | Lo | Sf | Lo | Mp | Mp | Lo | Jk | Lo | Jk | Sf | Sf | Jk | Lo | Jk | Mp | Jk | Sf | Jk | Jk | Mp | Jk | Jk |
Lo | Lo | Lo | Mp | Jk | Jk | Mp | Jk | Lo | Mp | Lo | Sf | Jk | Mp
millipo23
January 23, 2010 at 2:36 am
Very intriguing subject instrument bookmark your parcel to alter if you make writer roughly in the forthcoming.regardsjoy______________________________________________pet potty | pet potty | dog potty grass | pet potty | pet potty grass
millipo23
February 3, 2010 at 12:01 pm
Where can i have more info on this ?Thanksraven conway______________________________________________
Raleigh Painting Services
February 25, 2010 at 1:18 pm
It would also be very helpful to me if you made your additions available. Thanks!
Layne Moseley
March 11, 2010 at 6:13 pm
At the risk of sounding repetitive, I would fourth the above. I think you would be doing a great service to the community, since Apple's support for web services is sorely lacking at the moment.
edinburgh dentist
March 14, 2010 at 3:31 am