设为首页 收藏本站
查看: 765|回复: 0

[经验分享] php 使用zendstudio 生成webservice文件 wsdl

[复制链接]

尚未签到

发表于 2015-8-27 13:00:18 | 显示全部楼层 |阅读模式
  首先新建一个项目
  在项目中新建下面这些文件
  php类文件 test.php



<?php
class test {
public function __construct()
{
}
public function add($name,$age)
{
$result = array('REV'=>false);
$result['REV'] = true;
$result['DATA'] = 1;
$result = json_encode($result);
return $result;
}
public function del($id)
{
$result = false;
return $result;
}
public function getlist($type)
{
$result = array(
array('name'=>'张三','age'=>18),
array('name'=>'李四','age'=>20),
array('name'=>'jms','age'=>10),
array('name'=>'jk陈','age'=>8),
);
$result = json_encode($result);
return $result;
}
}
?>
  使用zendstudio生成wsdl文件
DSC0000.jpg DSC0001.jpg
  
DSC0002.jpg    DSC0003.jpg
  生成的文件格式如下



<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://localhost/t/ws" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="test_server" targetNamespace="http://localhost/t/ws">
<wsdl:types>
<xsd:schema targetNamespace="http://localhost/t/ws">
<xsd:element name="getlist">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="in" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="getlistResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="out" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="getlistRequest">
<wsdl:part name="type" type="xsd:int"/>
</wsdl:message>
<wsdl:message name="getlistResponse">
<wsdl:part name="resultRespose" type="xsd:string"/>
</wsdl:message>
<wsdl:portType name="test_server">
<wsdl:operation name="getlist">
<wsdl:input message="tns:getlistRequest"/>
<wsdl:output message="tns:getlistResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="test_serverSOAP" type="tns:test_server">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="getlist">
<soap:operation
soapAction="http://localhost/t/ws/NewOperation" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="test_server">
<wsdl:port binding="tns:test_serverSOAP" name="test_serverSOAP">
<soap:address location="http://localhost/t/ws/server.php"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
  
  调用server的文件 server.php



<?php
ini_set("soap.wsdl_cache_enabled", "0");  //测试时打开防止soap缓存
include("test.php");
$Server=new SoapServer('test_server.wsdl');   //SoapServer
$Server->setClass("test");
$Server->handle();
?>
  
  
  测试调用webserver wsdl的文件



<?php
ini_set("soap.wsdl_cache_enabled", "0");
//$url = 'http://localhost/t/ws/test_server.wsdl';
$url = 'http://localhost/t/ws/server.php?wsdl';    //两种url都可以
$client = new SoapClient($url);
$params = array('type'=>1);
$res = $client->__soapCall('getlist',array('parameters'=>$params));
var_dump($res);
?>
  返回数据:



string(119) "[{"name":"\u5f20\u4e09","age":18},{"name":"\u674e\u56db","age":20},{"name":"jms","age":10},{"name":"jk\u9648","age":8}]"
  调用成功
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-105054-1-1.html 上篇帖子: APMServ—我用过的最优秀的PHP集成环境工具 下篇帖子: PHP判断端口是否打开的代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表