User login |
PST! Don't tell anyone but consuming web services in PHP just got easyMy current contract required me to write some proxy classes for consuming a web service, they have a number of API's integrated with their application and all of them use nuSOAP - something I have quite a bit of experience with and I know all to well that API integration with nuSOAP involves alot of manual coding to do things like mapping associative arrays of complex SOAP types back into PHP objects. Not wanting to be labouring through loads of manual repetitive coding I managed to pursuade them to compile the built in PHP SOAP library (which handles type mapping automatically) and I started looking around for a PHP utility that would generate the proxy code for me. After alot of searching I eventually came across PST! (PHP SOAP Toolkit) which is a utility for manipulating WSDLs into code and vice versa, it is installed via PEAR and provides a command line utility that allows you to generate PHP classes from a WSDL location. It works by inspecting the WSDL and creating XML describing the web service and datatypes within in a format that represents PHP more closely. You can then have PST! either write the XML to files or automatically apply some XSLT stylesheets to create PHP classes, it is possible to have complete control over how the classes are generated by overriding the standard XSLT files with your own thus providing a really quick and flexible way of code generation. I used my own XSLT files to create a skeleton of unit tests for the web service and if you really wanted (and you would have to really, really want to ;-) you could create classes that used nuSOAP instead of the built in library. It's still in relatively early development but works a treat and I think it's a big, big step in getting PHP closer to the kind of ease that Java and .NET users enjoy when it comes to consuming web services.
Reply |