Home >Backend Development >PHP Tutorial >Example sharing of PHP publishing WebService
Web service is a platform-independent, low-coupling, self-contained, programmable web-based application. This article mainly shares with you examples of PHP publishing WebService, hoping to help everyone.
//发布WebService <?php header("Content-Type:text/html;charset=UTF-8"); //把 NuSOAP 的源文件包含到当前的代码文件里 require_once("nusoap.php"); function ssoRegister($unixname){ return "$unixname"; } //初始化服务对象 , 这个对象是类 soap_server 的一个实例 $server = new soap_server; //调用服务对象的 register 方法注册需要被客户端访问的程序。 //只有注册过的程序,才能被远程客户端访问到。 $server->soap_defencoding = 'UTF-8'; $server->decode_utf8 = false; $server->xml_encoding = 'UTF-8'; $server->configureWSDL('mysoapServer');//打开wsdl支持 $server->register( 'ssoRegister', //方法名 array("unixname"=>"xsd:string"), array("return"=>"xsd:string")); //isset 检测变量是否设置 $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; //service 处理客户端输入的数据 $server->service($HTTP_RAW_POST_DATA); ?>
<?php //调用WebService require 'nusoap.php'; $client = new nusoap_client($gfWsURL); $client->soap_defencoding = 'UTF-8'; $client->decode_utf8 = false; $client->xml_encoding = 'UTF-8'; $paras=array('unixname'=>'dyh'); $checkResult=$client->call('ssoRegister',$paras); ?>
Note: Please click to open the link to download the nusoap.php file
Related recommendations:
JS and WebService large file upload code sharing
Detailed explanation of Nodejs calling WebService
Detailed explanation of php creating and calling webservice interface instance
The above is the detailed content of Example sharing of PHP publishing WebService. For more information, please follow other related articles on the PHP Chinese website!