WSDL2PHP 2 Minutes Introduction

WSDL2PHP makes the development of web service providers and consumers quick and easy. I wrote a 2 minutes guide on developing web services providers sometimes ago. So lets concentrate on developing web service consumers here.

Where is WSDL2PHP?

WSDL2PHP script is included in the WSF/PHP packs. You can find the wsdl2php.php script inside the ‘scripts’ directory of any source or binary package. Or you can use the online wsd2php tool hosted in WSF/PHP web services DEMO Site.

How to Run the Script?

Here is the command

/scripts/wsdl2php.php mywsdl.wsdl > myclient.php

The Code is Generated. How Can I add My Code There?

It is simple. Just search for the comment “//TODO”.
Check for an example here.

You have to write custom code for 2 occasions per operation.

  1. To Provide Input Parameters
  2. To Handle output parameters.

An Example?

Here is the code snippet corresponding to the simpleAdd request for our demo WSDL.

    $input = new simpleAdd();
    //TODO: fill in the class fields of $input to match your business logic

    // call the operation
    $response = $proxy->simpleAdd($input);
    //TODO: Implement business logic to consume $response, which is of type simpleAddResponse

Here is how after I filled my logic in place of TODO comments.

    $input = new simpleAdd();
    //DONE: fill in the class fields of $input to match your business logic

    //-------my code----
    $input->param0 = 2;
    $input->param1 = 3;
    //------------------

    // call the operation
    $response = $proxy->simpleAdd($input);
    //DONE: Implement business logic to consume $response, which is of type simpleAddResponse

    //--------my code-----
    echo $response->return;
    //--------------------
This entry was posted in 2 minutes guide, Tutorial/Guide, web services, WSDL, wsf/php, wso2, xml schema and tagged , , , , , , , . Bookmark the permalink.

19 Responses to WSDL2PHP 2 Minutes Introduction

  1. Massimo says:

    wsdl2php is a nice tool, but it cannot cope with the xsd:import tags one finds in WSDLs generated by non-PHP frameworks.
    Are you going to address this shortcoming in a future release?

  2. dimuthu says:

    Hi Massimo,

    Yea. Surely.

    In fact xsd:import is already supported by wsdl2php except some exceptions like recursive imports, and sometime multiple imports of the same schema. We will surely address this issue in cumming releases.

    Thanks
    Dimuthu

  3. Massimo says:

    Dimuthu,

    Thanks for the quick reply. While we wait for an enhanced wsdl2php, do you know of a tool (or a simple manual way) to merge back all the external xsd files into the wsdl?

    I searched the net far and wide for such a tool, found many developers having the same issues but no real answers.

    To put matters in context, I am struggling with a wsdl importing several xsd schemas, but with my limited knowledge of the syntax and of namespace nuances have only achieved unsatisfactory results so far.

    As a side note, I remember in the beginning of SOAP that the wsdl was meant to simplify things for the developer and to maximize interoperability: after all these years it’s quite disappointing to realize those targets are still nowhere in sight.

    Thank you in advance,
    Massimo

  4. dimuthu says:

    Hi Massimo,
    I too haven’t meet a tool to merge imported xsds and imported wsdls. Anyway merging of imported xsds are very easy. You just need to copy the <schema></schema> part to the types element in the original wsdl.

    Anyway merging imported wsdls are not that straight forward since we should aware about the namespaces a lot in that process.

    I agree with the fact wsdls uses lot of strange constructs that are not much interoperable. In fact these specifications are lot flexible allowing people to innovate things around them. May be It is up to web service designers to be careful in designing their wsdls considering interoperability as a major issue.

    Thanks
    Dimuthu

  5. rickard says:

    Am new to php devlopement but a experience java developer, so you have to excuse this newbiee question.

    Do I have to install the whole wso package to get this running or can I just include some php scripts on my site ?

    Can see from the generated proxy that it uses a class called WSClient which in my belief is a custom class from wso.

    Thanks

  6. Uma says:

    Dear Author or Readers,

    I have a question where i need to pass objects as an argument instead of simple types. WSDL was buillt using JAVA axis. I thought i can easily integrate the WSDL in to php because php is peace of cake..

    Any insight on this? Does your works for this kind of things?

    My WSDL look like this.

  7. Uma says:

    WSDL is missing ..might be because of the xml

  8. dimuthu says:

    @rickard: Yea you have to install the wsf/php extension. WSClient, WSService classes comes from this extension.

    @Uma: Yea, you can use complex types with wsf/php. If you have any doubt use the WSF/PHP forum. You will be able to attach your wsdl there.

    Thanks
    Dimuthu

  9. Massimo says:

    Hi dimuthu,

    This is just to let you – and the readers of this blog – know I found a way to merge/flatten imported XSDs and/or included WSDLs back into a single WSDL that wsdl2php can easily understand.

    One just downloads and installs gSOAP from http://www.cs.fsu.edu/~engelen/soap.html, then it’s simply:

    1) wsdl2h -s MultiFile.wsdl
    2) soapcpp2 -S -L MultiFile.h

    This sequence creates (among others) a single MultiFileSoapBinding.wsdl with all the information initially split up throughout the input files.

  10. swadams says:

    I can’t install wsdl2php. When I try to, I always get “The extension ‘zlib’ couldn’t be found. Please make sure your version of PHP was built with ‘zlib’ support.” I added the “–with-zlib” option to PHP’s configuration and I’m still getting the same error. I used phpinfo() to confirm that PHP was configured with this option. I also ran the test script at http://us3.php.net/manual/zh/ref.zlib.php to make sure zlib is actually working and it is. What could be causing this?

  11. dimuthu says:

    Hi swadams,
    This should be some problem in library versions. FYI My PHP version is 5.2.6, zlib 1.2.3, and wsf/php 2.0.0

    What are your versions?

    Thanks
    Dimuthu

  12. swadams says:

    My PHP and zlib versions are the same as yours and I’m not using wsf/php. I configured PHP with no directory specified after “–with-zlib”. I don’t know if that has anything to do with it or not.

  13. dimuthu says:

    Hi swadams,
    WSF/PHP should not depend on zlib. Anyway what WSF/PHP pack you tried with? source or binary. If it is binary please check compiling source.
    This can be due to some other reasons like incompatible libxml2 libs (my version is 2.6.31) or some older wsf/php libraries already in the path. Anyway I haven’t got this error message. Can you check whether you have other error messeges in php log.

    Dimuthu

  14. JohnDoe says:

    The online demo apears to be broken. http://labs.wso2.org/wsf/php/wsdl2phptool.php I tried it with the sample wsdl, and an other wsdl and it is just emitting errors.

  15. dimuthu says:

    Fixed. This caused by the recent server migration we did. Thanks for letting us know.

  16. zaker says:

    Sorry Massimo, but i have problems with what you are saying here:
    http://www.dimuthu.org/blog/2008/09/21/wsdl2php-2-minutes-introduction/#comment-1009
    I cant create a merged WSDL using your method of two steps.
    i’m using gSOAP v2.8.1 stable under Windows XP

  17. Bob Kennedy says:

    I edited the code with my input parameters and a print_r($response) for the result. When I ran the script, my browser gave me the option to download it and when I did, it was empty. The same thing happened when I replaced the ‘print_r($response)’ with ‘echo “hi”;’

    It’s like there are headers being passed to force a download or something. Any ideas on a remedy or what I’m doing wrong?

  18. Bob Kennedy says:

    A little update. I tried it in a couple different browsers and it appears that it’s just not sending any response, and FireFox got confused. I commented out the line where I try to perform an operation specified in the wsdl, (like $proxy->DoActionAndGiveResponse($input);) and the script finished fine (except, of course, for not giving me a response from the service.)

    Any ideas what could cause that? Also, is there a way of connecting to the service to see what operations are available? Like with PHP’s SOAPClient $client->__getFunctions(); Then I’d at least know SOMETHING was going right.

  19. qalhat says:

    @swadams

    I faced same issue installing wsdl2php using pear (caused by another installation of php on my laptop), I fixed it by specifying the full path to pear on my working php installion:

    # /usr/local/Zend/Core/bin/pear install wsdl2php-0.2.1-pear.tgz

Leave a Reply

Your email address will not be published. Required fields are marked *