WebService fabrication of Nusoap complex objects

Source: Internet
Author: User
Tags wsdl

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-&GT;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> ';?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.