Home  >  Article  >  Backend Development  >  php nusoap creates and calls webservice

php nusoap creates and calls webservice

WBOY
WBOYOriginal
2016-07-30 13:31:35902browse

Original text: http://blog.csdn.net/painstaker/article/details/5870515

NuSoap is a WebService programming tool in the PHP environment. It is used to create or call WebService. It is an open source software. It is completely written in PHP language and is a series of PHP classes that send and receive SOAP messages through HTTP. It is developed by NuSphere Corporation (http://www.nusphere.com/).
Its advantage is that it does not require extension library support. This feature makes it usable in all PHP environments and is not affected by server security settings.
1. First, go to http://sourceforge.net/projects/nusoap/ to download nusoap-0.9.5.zip, unzip it and put the lib folder in the same directory as your WebService program, such as /WebService/ lib.
2. Server side: Create the nusoapService.php file.

require_once("lib/nusoap.php");
$server = new soap_server;
//Avoid garbled characters
$server->soap_defencoding = 'UTF-8';
$server->decode_utf8 = false;
$server->xml_encoding = 'UTF-8';
$server->configureWSDL('sayHello');//openwsdl Support
/*
Register the program that needs to be accessed by the client
Type corresponding value: bool->"xsd:boolean" &String-& gt; "XSD: String" int-& gt; "XSD: Int" Float-& GT;

'sayHello'
, //Method name array("name"
=>"xsd:string"), // , Parameter, the default "XSD: String" Aarray ( "return" = & gt;
"xsd: string"
) ; = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
//service Process data entered by the client
$server->service($HTTP_RAW_POST_DATA ); / ** * Methods for calling * @param $name*/
function sayHello($name) {return "Hello, {$name
}!"
 ; parsing SOAP payload on line x(line number): Reserved XML Name


2. should be in UTF-8 No BOM format saving, otherwise the client call will make an error. 3.Client: Create the nusoapClient.php file. require_once("lib/nusoap.php"); /*
Passed WSDLCall WebService
Parameters 1 The address of the WSDL file (wsdl after the question mark cannot be capitalized) WSDL
$client = new soapclient ('http://localhost/WebService/nusoapService.php?wsdl',true);                                                                                         new soapclient('http://localhost/WebService/nusoapService.php'
);

$client->soap_defencoding = 'UTF-8';$client->decode_utf8 = false; $client->xml_encoding = 'UTF-8'; //Parameters are transferred in array form $paras=array('name' => 'Bruce Lee'); //When the target method has no parameters, the following parameters can be omitted sayHello' ,$paras); //Check the error and get the return value if (!$err= $client-> getError()) { echo "return result: ",$result; ) }?>Note: use nusoap to implement WebService, do not enable php’s SOAP extension The above introduces how to create and call webservice with php nusoap, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Linux--install nginxNext article:Linux--install nginx