Original: http://blog.csdn.net/painstaker/article/details/5870515
Nusoap is a WebService programming tool in the PHP environment for creating or invoking WebService, an open source software. It is written entirely in PHP, a series of PHP classes that send and receive SOAP messages over HTTP, by Nusphere Corporation (http://www.nusphere.com/Development
Its advantage is that it does not require the support of the extension library, which makes it available to all PHP environments and is not affected by server security settings.
1. First, go tohttp://sourceforge.net/projects/nusoap/Download Nusoap-0.9.5.zip, unzip the Lib folder into the same directory as your WebService program, such as/webservice/lib.
2. Server: Establish nusoapservice.php file.
require_once("lib/nusoap.php");
$server=NewSoap_server;
//Avoid garbled characters
$server->soap_defencoding =' UTF-8 ';
$server->decode_utf8 =false;
$server->xml_encoding =' UTF-8 ';
$server->configurewsdl (' SayHello ');//OpenWSDLSupport
/*
registering programs that need to be accessed by clients
type corresponding value:bool-> "Xsd:boolean"String-> "Xsd:string"
Int-> "Xsd:int" float-> "Xsd:float"
*/
$server->register (' SayHello ', //Method Name
Array("Name"="Xsd:string"), //parameter, which defaults to"Xsd:string"
Array("Return"="Xsd:string") );//return value, default is"Xsd:string"
//issetdetect if a variable is set
$HTTP _raw_post_data= isset($HTTP _raw_post_data) ?$HTTP _raw_post_data:'';
//serviceprocessing data entered by the client $server->service ($HTTP _raw_post_data);
/**
*method to invoke
* @param $name
*/
functionSayHello ($name) { return"Hello,{$name}!"; }?>Note: 1.file code cannot have any output,Otherwise, the call will report an error similar to the following:
XML Error parsing SOAP payload on line x (Line number): Reserved XML Name
2.to takeUTF-8NoBOMformat is saved, or the client call will be faulted.
3.Client: Buildnusoapclient.phpfile. require_once("lib/nusoap.php"); /*
throughWSDLcalledWebService
Parameters1 WSDLthe address of the file(after the question markWSDLcannot be uppercase)
Parameters2Specifies whether to useWSDL
$client = new SoapClient (' http://localhost/WebService/nusoapService.php?wsdl ', true);
*/
$client=NewSoapClient (' http://localhost/WebService/nusoapService.php '); $client->soap_defencoding =' UTF-8 '; $client->decode_utf8 =false; $client->xml_encoding =' UTF-8 '; //parameter to array form pass $paras=Array(' name '=' Bruce Lee '); //The following arguments can be omitted when the target method has no arguments $result=$client->call (' SayHello ',$paras); //Check for errors, get return values off(!$err=$client->geterror ()) { Echo"return Result:",$result; } Else{ Echo"Error Calling:",$err; }?>
Note:withNusoapImplementWebService,Do not openPHPof theSOAPExtended
The above describes the PHP Nusoap create and call WebService, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.