Wednesday, July 4, 2012

WSDL to PHP – Generate PHP code from a WSDL file

There are many classes available to generate a WSDL file from PHP. But I wanted to create PHP classes out of a WSDL file. SOAP allows passing complex data around and to write a SOAP client, I need to have classes defined in PHP for these complex data. I did not want to manually go through WSDL and create different data types based on SOAP declarations. As a matter of fact, I wanted something that will create a SOAP Server stub for me out of the WSDL (not just a client!)
Now I did not find something that will create a SOAP Server, but I found two implementations that create a SOAP Client out of WSDL. This is still a good start, and I can do some further hacks to create a SOAP server.
Here are these two approaches:
  • WSDLInterpreter – WSDLInterpreter is a library that creates PHP 5 classes based on a WSDL document. It creates a SOAPClient via XSLT transformations. Unlike other wsdl2php solutions, WSDLInterpreter utilizes the WSDL document as its source of information, as opposed to the native SoapClient interpretation of the WSDL document. This allows for proper class inheritance, naming convention correction, and method overloading with proper method signature verification using strict type checking.
  • wsdl2php – wsdl2php is a very simple tool for PHP 5 to generate client code against a WSDL-file. It uses DOM to parse the WSDL and generates PHP code out of it.
Both approaches generate similar output. And are a great start if you want to use a third party web service in your PHP code.

0 comments:

Post a Comment