webservices using soap and wsdl

Page 8

Building a WSDL File WSDL files can be cumbersome to write by hand as they must contain specific tags and are usually quite long. The nice thing about using NuSOAP is that it can create a WSDL file for you! Let's modify the SOAP server we made in the first article to accommodate this. Open productlist.php and change it to reflect the code below: 01 <?php 02 require_once "nusoap.php"; 03 04 function getProd($category) { 05 if ($category == "books") { 06 return join(",", array( 07 "The WordPress Anthology", 08 "PHP Master: Write Cutting Edge Code", 09 "Build Your Own Website the Right Way")); 10 } 11 else { 12 return "No products listed under that category"; 13 } 14 } 15 16 $server = new soap_server(); 17 $server->configureWSDL("productlist", "urn:productlist"); 18 19 $server->register("getProd", 20 array("category" => "xsd:string"), 21 array("return" => "xsd:string"), 22 "urn:productlist", 23 "urn:productlist#getProd", 24 "rpc", 25 "encoded", 26 "Get a listing of products by category"); 27 28 $server->service($HTTP_RAW_POST_DATA); Basically this is the same code as before but with only a couple of changes. The first change adds a call to configureWSDL(); the method acts as a flag to tell the server to generate a WSDL file for our service. The first argument is the name of the service and the second is the namespace for our service. A discussion of namespaces is really outside the scope of this article, but be aware that although we are not taking advantage of them here, platforms like Apache Axis and .NET do. It's best to include them to be fully interoperable.


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.