in Technology

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.

Write a Comment

Comment

12 Comments

  1. Hi,

    Can WSDLInterperter or WSDL2PHP generate a SOAP client from a WSDL? If yes, would you please tell me how do i do this. I have read the instructions, but couldn’t get these to work.

  2. hello i’m a .net developer and i have a client that want to generate stub classes using the wsdl.

    the webservice was developed by me so i need to gave him suport but i realy don’t understand nothing about php.

    can you provide me some samples. how can i pass a wsdl url and get the stub classes?

    best regards

  3. I suggest your client get a PHP developer. It won’t be easy to deploy a web service without someone who knows PHP. Someone who’s done some PHP work, can easily use any of the tools I mentioned in the blog and generate stub class.

    Alternatively, you can create a client in C# and ask the client to rewrite it in PHP. The syntax and logic is quite similar between C# and PHP.

    HTH.

  4. Is there a way to use the wsdl to generate the web server stubs instead of the client stubs. We have a need to build identical web services. One of them needs to be done in PHP. We already have one to use as a template that is written in .NET

  5. Hi,

    I jutst finished my own Wsdl To Php generator. This package allows to programmatically send request to a SOAP service using PHP classes. In order to that, this class generates each class for each request and each request parameters and each request response. Each class is stored in a hierarchical folder/sub-folder. The SOAP client is then abstracted and you only deal with objects representing the WSDL.
    It uses eZ Components, ezcPhpGenerator, in order to generate php files.
    Feel free to test it and comme back to me if it’s buggued 😉 : https://sourceforge.net/projects/wsdltophp/