php的webservice例一(已测试)

上一篇 / 下一篇  2007-12-02 12:39:10

  • 下载nusoap类库
  • 创建webservice服务器端文件. server.php .代码如下
<?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即可看到结果

TAG: webservice php

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

数据统计

  • 访问量: 1526
  • 日志数: 3
  • 建立时间: 2007-02-02
  • 更新时间: 2007-12-02

RSS订阅

Open Toolbar