Example sharing of PHP publishing WebService

小云云
Release: 2023-03-21 17:28:01
Original
2608 people have browsed it

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 = &#39;UTF-8&#39;;
    $server->decode_utf8 = false;
    $server->xml_encoding = &#39;UTF-8&#39;;
    $server->configureWSDL(&#39;mysoapServer&#39;);//打开wsdl支持
    $server->register( &#39;ssoRegister&#39;,    //方法名
    		        array("unixname"=>"xsd:string"),
			array("return"=>"xsd:string"));
    //isset 检测变量是否设置
    $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : &#39;&#39;;
    //service 处理客户端输入的数据
    $server->service($HTTP_RAW_POST_DATA);
?>
Copy after login
<?php
    //调用WebService
    require &#39;nusoap.php&#39;;			
    $client = new nusoap_client($gfWsURL);
    $client->soap_defencoding = &#39;UTF-8&#39;;
    $client->decode_utf8 = false;
    $client->xml_encoding = &#39;UTF-8&#39;;

    $paras=array(&#39;unixname&#39;=>&#39;dyh&#39;);
    $checkResult=$client->call(&#39;ssoRegister&#39;,$paras);

?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template