php的webservice例一(已测试)
上一篇 /
下一篇 2007-12-02 12:39:10
<?php
ini_set("include_path","../");
ini_set("error_reporting","E_ALL & ~E_notice");
require_once("lib/nusoap.php");
/**
* 返回字符串
*
* @return string
*/
function helloworld()
{
return array("name"=>"cjz","gender"=>"male");
}
/**
* 加法
*
* @param int $x
* @param int $y
* @return int
*/
function add($x,$y)
{
return $x+$y;
}
$server = new soap_server();
$server->register("helloworld");
$server->register("add",array($x,$y));
if (phpversion()=="5.2.2")
{
$GLOBALS['HTTP_RAW_POST_DATA'] = file_get_contents("
php://input");
}
$server->service($GLOBALS['HTTP_RAW_POST_DATA']);
- 客户端文件,client.php
<?php
require_once("lib/nusoap.php");
$serviceurl = "http://localhost:8080/webservice/server.php";
$soapclient = new soapclient($serviceurl);
$params = array(4,2);
$quote1 = $soapclient->call("helloworld");
echo "helloworld function: ".$quote1["name"]."--".$quote1["gender"];
echo "<br />";
$quote2 = $soapclient->call("add",$params);
echo "add function:{$params[0]}+{$params[1]} = ".$quote2;
在浏览器里输入http://localhost:8080/webserver/client.php即可看到结果
相关阅读:
- 这个论坛果然不错,大家都来做个统计吧!~ (心蓝Edward, 2007-11-28)
- PHP汉字验证码的实现 (thaiki, 2007-11-29)
- 入门级PHP程序员面试题(总100分/47题), 看你能回答多少? (lycoo, 2007-11-29)
- php 常用学习站点 (heamon, 2007-11-29)
- php5.2 的 php.ini 中文版配置详细说明(1) (choiniao, 2007-11-30)
- Ghoul:PHP,Web与互联网 (Ghoul, 2007-11-30)
- [转]Add Google Adsense to phpBB First Post and Last Post (dennis, 2007-11-30)
- [转]Add Google Adsense To The phpBB Index Page (dennis, 2007-11-30)
- X-space的网址很混乱 (Ghoul, 2007-11-30)
- 怎样才能成为PHP高手?学会 (choiniao, 2007-12-01)
导入论坛
收藏
分享给好友
管理
举报
TAG:
webservice
php