php wsdl生成类,无需任何组件去年在深圳上班,由于网站要与一个.net下的网页游戏整合,考虑到的就是wsdl接口,写了篇日记关于wsdl的,当时用的是zend生成的,php wsdl zend生成,最近这从百度搜来这个问题的朋友不少哈,有些朋友发email不知道怎么用zend搞,zend生成其实很简单啦,不过现在找了这个类更简单,国外的人写的,客户端和服务端代码我整了个示例,看下就明白的。
<?php
/**
+——————————————————————————
* wsdl客户端
+——————————————————————————
* @wsdl客户端发送
* @Author 犇<admin@huqiao.net>
* @Copyright (c) www.huqiao.net
+——————————————————————————
*/
$client = new SoapClient(“http://127.0.0.1/createsoap/hello.wsdl”);
try {
$result = $client->myfunc(‘789′);
var_dump($result);
//echo “The answer isresult”;
}
catch (SoapFault $f){
echo “Error Message: {$f->getMessage()}”;
}
?>
<?php
/**
+——————————————————————————
* wsdl服务端
+——————————————————————————
* @wsdl服务端接收
* @Author 犇<admin@huqiao.net>
* @Copyright (c) www.huqiao.net
+——————————————————————————
*/
define(‘WSDL_URL’,'hello.wsdl’); //定义WSDL文件路径
ini_set(’soap.wsdl_cache_enabled’,'0′); //关闭WSDL缓存
//WSDL文件不存在时自动创建
if(!file_exists(WSDL_URL))
{
require_once ‘SoapDiscovery.class.php’;
$disco = new SoapDiscovery(‘Mywsdl’,'www.zhuoqu.com’);
$str = $disco->getWSDL();
file_put_contents(WSDL_URL,$str);
}
//SOAP开启并接收Client传入的参数响应
$server = new SoapServer(WSDL_URL);
$server->setClass(‘Mywsdl’);
$server->handle();
//测试定义公开的类
class Mywsdl {
private $nombre = ”;
public function __construct($name = ‘World’)
{
$this->name = $name;
}
public function greet($name = ”)
{
$name = $name?$name:$this->name;
return ‘Hello ‘.$name.’.';
}
public function serverTimestamp()
{
return time();
}
public function myfunc($a=”){
return $a;
}
}
?>
评论30