Luckily for me somebody thought of it first. Enter wsdl2php. It is simple, lightweight and easy to use. It parses the wsdl file and creates ready to use php classes. It is really handy for tackling those complex data types that you might have on your web services. It can be used both on Linux and Windows from the php command line.
So go ahead and download the latest version from sourceforge. If you are on a Linux distribution you can use the pear installer to install it from the .tgz file:
sudo pear install wsdl2php-0.2.1-pear.tgz
and then use it as a command line app with:
wsdl2php http://yoursoapserver/Service.wsdl
If you are on Windows, no worries, you can also extract the tgz and call the wsdl2php.php file from the command line with the URL to the WSDL as an argument. Something like:
C:\PHP5\php.exe -f "C:\wsdl2php\wsdl2php.php" -- "http://yoursoapserver/Service.wsdl"
There are also more info how to use php cli under windows on the php manual pages.
The script should generate a php file in the working directory with all the classes and data types that are found on the WSDL. The generated client class extends php's SoapClient class, which shold come with the php core. You just have to include it in your php app, and you are ready to go:
require_once 'YourWebService.php';
$client = new yourWebService();
$input = "Your Input"; # check the generated classes to find out
# what the required input should be.
try{
echo $client->someFunction($input);
}
catch (Exception $e){
echo $e->getMessage();
}
If you are dealing with complex data types, be sure to check the generated classes to determine what your input variables should look like.
If you learn to use this tool, it should make your work with SOAP and WSDL a lot easier.
However if you are struggling to hard and still can not make a soap client work with a wsdl file and generate the desired XML output read my blog post about posting raw XML with nusoap to a SOAP Web Service