Warning: This is hardcore dorkage, not some soft core widget for your blog. You have been warned. Go browse Youtube cat videos now if your brain is easily overwhelmed.
My client presented me with a 9-page-long WSDL document including complex types, and requested that I write code to talk to the service. WSDL stands for web services definition language, and it’s supposed to define XML for how you talk to web services — sort of a Rosetta Stone for mapping your whatever data into their neat little expectations. WSDL’s pull in namespaces and junk from all over the internets. Like any XML language they are much easier for machines to read than for people — the whole point of them is to be machine readable so that people don’t have to.
Since I no longer had a business running legacy PHP4 code, I had upgraded my last holdout PHP4 server to PHP5 several months ago and kicked my clients’ butt until they did also. Cool! Now I can use the native PHP5 SOAP extension that’s written in C and is blazingly fast and supposedly a lot smarter. Old deprecated solutions written in PHP like nusoap and the PEAR SOAP package were pokey and you had to set up the XML request yourself. Supposedly the PHP5 SOAP extension can just read the WSDL and do everything for you automagically. It worked quite nicely in all the hello world examples where you just input a zip code and find out the current temperature in that area or something simple like that. But it appeared to bork on complex types. Maybe it wasn’t really borking, but when the programmer still has to parse nested XML of data descriptors and get everything just right errors can happen. I am really bad at that, and even if you are awesome at it, it’s still a pain in the ass.
So I stumbled on wsdl2php — a tool for generating proxy classes for web services. I don’t have to install wsdl2php on my client’s box. It’s just a tool for me to use. I fed my client’s WSDL into that puppy and it generated a bunch of really boring boilerplate for me that I would have made numerous typos trying to do by hand. I included all those bogus data only classes, instantiated the ones I needed, and fed them to the proxy class. Once I realized that I had print instead of print_r on the object that the service returns (you can’t “print” an object) I realized that it was setting up the complex request perfectly and getting an appropriate response for the bogus data I was feeding it. Now my only problem is getting the client to provide me with data that’s not merely grammatical according to the WSDL, but also actually valid, so I can actually get some useful answers from the service.