Recommended URL:
Http://www.scottnichol.com/nusoapprogwsdl.htm
Excerpt from the following sections:
Server-side Programs
<?PHP//Pull in the nusoap coderequire_once(' nusoap.php ');//Create the server instance$server=Newsoap_server ();//Initialize WSDL Support$server->CONFIGUREWSDL (' hellowsdl2 ', ' URN:HELLOWSDL2 ');//Register The data structures used by the service$server->wsdl->Addcomplextype (' Person ', ' complexType ', ' struct ', ' all ', ',Array( ' FirstName ' =Array(' name ' = ' FirstName ', ' type ' = ' xsd:string '), ' age ' =Array(' name ' = ' age ', ' type ' = ' xsd:int '), ' gender ' =Array(' name ' = ' gender ', ' type ' = ' xsd:string ') ));$server->wsdl->Addcomplextype (' Sweepstakesgreeting ', ' complexType ', ' struct ', ' all ', ',Array( ' Greeting ' =Array(' name ' = ' greeting ', ' type ' = ' xsd:string '), ' winner ' =Array(' name ' = ' winner ', ' type ' = ' Xsd:boolean ') ));//Register The method to expose$server->register (' Hello ',//Method Name Array(' person ' = ' tns:person '),//Input Parameters Array(' return ' = ' tns:sweepstakesgreeting '),//Output Parameters' Urn:hellowsdl2 ',//namespace' Urn:hellowsdl2#hello ',//SOAPAction' RPC ',//style' Encoded ',// Use' Greet a person entering the sweepstakes '//Documentation);//Define the method as a PHP functionfunctionHello$person) { $greeting= ' Hello, '.$person[' FirstName ']. ‘. It's nice to meet a '.$person[' Age ']. ' Year old '.$person[' Gender ']. ‘.‘; $winner=$person[' firstname '] = = ' Scott '; return Array( ' Greeting ' =$greeting, ' winner ' =$winner );}//Use the request to invoke the service$HTTP _raw_post_data=isset($HTTP _raw_post_data) ?$HTTP _raw_post_data: ‘‘;$server->service ($HTTP _raw_post_data);?>
Client program:
<?PHP//Pull in the nusoap coderequire_once(' nusoap.php ');//Create the client instance$client=NewSoapClient (' http://localhost/phphack/hellowsdl2.php?wsdl ',true);//Check for an error$err=$client-GetError ();if($err) { //Display the error Echo' $err. ' </pre> '; //at this point, you know the follows would fail}//Call the SOAP method$person=Array(' FirstName ' = ' Willi ', ' age ' = ', ' gender ' = ' male ');$result=$client->call (' Hello ',Array(' person ' = =$person));//Check for a faultif($client-fault) { Echo' ; Print_r($result); Echo' </pre> ';} Else { //Check for errors $err=$client-GetError (); if($err) { //Display the error Echo' $err. ' </pre> '; } Else { //Display The result Echo' ; Print_r($result); Echo' </pre> '; }}//Display the request and responseEcho' ;Echo' <pre> '.Htmlspecialchars($client->request, Ent_quotes). ' </pre> ';Echo' ;Echo' <pre> '.Htmlspecialchars($client->response, Ent_quotes). ' </pre> ';//Display the Debug messagesEcho' ;Echo' <pre> '.Htmlspecialchars($client->debug_str, Ent_quotes). ' </pre> ';?>