10. Using WSDL

In the WSDL mode, by providing a WSDL file, you can invoke a service or provide a service, without having to construct the payload manually. Few simple steps are required to configure either the client or the service to use the WSDL mode.

10.1. Writing a Simple Client to Use the WSDL Mode

The sample.wsdl WSDL file provided in the samples\wsdl_mode folder will be used for the samples in this manual. Please have a look at the samples\wsdl_mode\sample.wsdl.

First obtain a WSClientProxy object from the WSClient as follows:

        $client = new WSClient(array("wsdl"=>"sample.wsdl"));
        $proxy = $client->getProxy();
    

Now you can call any operation defined in the sample.wsdl WSDL directory on the WSClientProxy object. For example,nvoke the echoString operation defined in sample.wsdl, as follows. invoke the echoString operation defined in sample.wsdl, as follows.

        $value = $proxy->echoString("Hello");
    

This call will construct the SOAP envelope with the required payload and send it to the service endpoint specified in the WSDL.

10.2. Writing a Simple Service to Use the WSDL Mode

We will implement a service to accept the request sent by the above client.

First write a function corresponding to the echoString operation defined in the WSDL.

        function echoFunction($value){
            return $value;
        }
    

Now we can map this function to the echoString operation as follows.

        $operations = array("echoString"=>"echoFunction");
        $opparams = array("echoFunction"=>"MIXED");
    

Here we are indicating to the service that the echoFunction is not a function that accepts a WSMessage instance as the sole argument, but a function with mixed arguments.

        $service = new WSService(array("wsdl"=>"sample.wsdl", 
            "operations"=>$operations,
            "opParams"=>$opparams));

        $service->reply();
    

10.3. WSDL Generation for a Given Service

WSDL Generation in WSO2 WSF/PHP is done using PHP reflection and an annotation parser. In order to generate a WSDL from a given WSO2 WSF/PHP service, a '?wsdl' request or a '?wsdl2' request should be sent to the server. '?wsdl' serves WSDL version 1.1, and '?wsdl2' serves WSDL version 2.0. For example, if you want to generate the WSDL for the service echoService.php, a request should be sent as,

http://localhost/echoService.php?wsdl

or

http://localhost/echoService.php?wsdl2

For more information on the annotation syntax, please have a look at the WSDL generation API document.