在网上找了很多制作PHP的Web Service的例子,但是都不太全面。以下是我的php制作过程。
1. 首先制作提供WebService的php页面。
//myservice.php
<?php
class service
{
public function HelloWorld()
{
return ”Hello”;
}
public function Add($a,$b)
{
return $a+$b;
}
}
//TestSoap.wsd需要在后面采用Zend Studio生成。
$server=new SoapServer(‘TestSoap.wsdl’,array(’soap_version’ => SOAP_1_2));
$server->setClass(“service”);
$server->handle();
?>
2.生成WSDL文件。采用Zend Studio生成。
生成过程:选择菜单File–>Export–>PHP->WSDL FILE
也就是出现下面的图
选择 next ,出现如下WSDL选择画面
File Name:选择需要生成的WSDL文件存储文件名和路径
Exported file 选择学要前面写的myservice.php文件,可以添加多个。
Classes:选择需要制作WebService的文件,注意:URL:一定要写上myservice.php的 URL.如果提供服务的是其他php页面,那就换成其他的php服务页面。
Global Settings:如下图所示:
选择Finish,生成WSDL文件,下面是Zend Studio里的效果图
3.客户端调用该Web Service
//Client.php
<?php
$a=new SoapClient(“TestSoap.wsdl”);
echo $a->HelloWorld();
echo(“<br />”);
echo $a->Add(1,2);
?>
到此为止,一个简单的Php WebService制作完成。
扩展:如何用WebService实现数据库的GRUD操作,后续发布。
补充:
TestSoap.wsdl文件到底是什么
<?xml version=’1.0′ encoding=’UTF-8′?>
<!– WSDL file generated by Zend Studio. –>
<definitions name=”TestSoap” targetNamespace=”urn:TestSoap” xmlns:typens=”urn:TestSoap” xmlns:xsd=”http://www.w3.org/2001/XMLSchema” xmlns:soap=”http://schemas.xmlsoap.org/wsdl/soap/” xmlns:soapenc=”http://schemas.xmlsoap.org/soap/encoding/” xmlns:wsdl=”http://schemas.xmlsoap.org/wsdl/” xmlns=”http://schemas.xmlsoap.org/wsdl/”>
<message name=”Add”>
<part name=”a”/>
<part name=”b”/>
</message>
<message name=”AddResponse”>
<part name=”AddReturn”/>
</message>
<message name=”HelloWorld”/>
<message name=”HelloWorldResponse”>
<part name=”HelloWorldReturn”/>
</message>
<message name=”Sub”>
<part name=”a”/>
</message>
<message name=”SubResponse”>
<part name=”SubReturn”/>
</message>
<portType name=”servicePortType”>
<operation name=”Add”>
<input message=”typens:Add”/>
<output message=”typens:AddResponse”/>
</operation>
<operation name=”HelloWorld”>
<input message=”typens:HelloWorld”/>
<output message=”typens:HelloWorldResponse”/>
</operation>
<operation name=”Sub”>
<input message=”typens:Sub”/>
<output message=”typens:SubResponse”/>
</operation>
</portType>
<binding name=”serviceBinding” type=”typens:servicePortType”>
<soap:binding style=”rpc” transport=”http://schemas.xmlsoap.org/soap/http”/>
<operation name=”Add”>
<soap:operation soapAction=”urn:serviceAction”/>
<input>
<soap:body namespace=”urn:TestSoap” use=”literal”/>
</input>
<output>
<soap:body namespace=”urn:TestSoap” use=”literal”/>
</output>
</operation>
<operation name=”HelloWorld”>
<soap:operation soapAction=”urn:serviceAction”/>
<input>
<soap:body namespace=”urn:TestSoap” use=”literal”/>
</input>
<output>
<soap:body namespace=”urn:TestSoap” use=”literal”/>
</output>
</operation>
<operation name=”Sub”>
<soap:operation soapAction=”urn:serviceAction”/>
<input>
<soap:body namespace=”urn:TestSoap” use=”literal”/>
</input>
<output>
<soap:body namespace=”urn:TestSoap” use=”literal”/>
</output>
</operation>
</binding>
<service name=”TestSoapService”>
<port name=”servicePort” binding=”typens:serviceBinding”>
<soap:address location=”http://localhost/test/soap/myservice.php”/>
</port>
</service>
</definitions>
但是我发觉他和.net 产生的WSDL不一样。而且通过这种方式有一个弊端,如果我的Service里添加了一个新的方法,需要在重新生成WSDL文件,
而且还经常出错误。但是如果采用Zend WSDL编辑器产生的WSDL感觉更标准写,而且他相对于目前这样的方法不需要删除WSDL重新建,只需要编辑目前已有的。
- 大小: 30.6 KB
- 大小: 47.7 KB
- 大小: 31.2 KB
- 大小: 41.4 KB
分享到:
相关推荐
该文档详细描述了利用Zend Studio for Eclipse 生成wsdl文件,用php编写提供web service 的服务程序,然后用php调用,亲测通过
随着WebService技术的普及,Eclipse也提供了相应的支持,允许开发者通过wsdl文件生成Java客户端。本文将详细介绍如何在Eclipse中使用wsdl文件生成Java客户端。 首先,让我们了解什么是wsdl文件。Wsdl(Web Services...
Eclipse根据wsdl文件逆向生成webservice客户端项目源码,包括wsdl文件,测试示例,测试webservice代码,包含备注信息
Eclipse根据wsdl文件自动生成webservice client图解,以及调用示例,附测试项目。源码示例,包括两个wsdl文件
ZendStudio--WSDL 在php中使用soap(webservice),有时候要用到wsdl文件,如果自己...好在zde为我们提供了自动生成wsdl的功能,在zend studio9中,与之前版本不一样的是,你需要单独安装wsdl插件,才可以使用,步骤如下
基于 Apache Axis2 将上述类的方法对外提供 Web 服务,生成 WSDL 文件,以及调用 服务 2019-12-23根据全网的教程搭建最详细的教程 源码太大上传不了,但是教程内容十分详细,跟着我的教程一步一步就可以搭建起来,...
soapui测试工具调用wsdl生成方式
WebService的WSDL文件生成Java代码工具
根据WSDL文件生成客户端代码与创建客户端工程 注意小细节:在根据对方提供的webservice地址,先将对方webservice的wsdl文件描述文件保存到本地时,格式先保存为xml,后将其后缀名为.wsdl的文件 否则报:...
Eclipse中用wsdl生成java客户端.pdf
通过此方法可以把webservice接口通过接口生成的wsdl文件生成本地调用代码,详细配置可以查看wsdl2_java登入.bat文件,此包原来放在H盘根目录,双击wsdl2_java登入.bat文件即可以生成Create文件夹中的JAVA代码
里面写了6步,完成soap服务器的配制,和WSDL生成 教你怎么写生成WSDL文件的bat命令 有相关的包
webService接口用eclipse工具WSDL生成服务端和客户端(http协议,xml构造传输),本人研究了好几天已成功,希望大家参考帖子少走弯路
非常好的,非常有难度的wsdl
我开发esb接口时自己基于.net4.0开发的一个wsdl生成工具
php实现soap服务快速生成wsdl的完整代码,包括客户端测试。前提是php支持soap扩展,soap的配置在此不涉及。 特别注意的一点是:soap服务端源码在 <?php ... ?> 之外不允许有任何空格或空行。
对于WebServers的通信协议,根据客户提供的WSDL文件生成接口文件,免去到客户现场连内网下载的时间。亲测可用。C# VB.NET可用
eclipse根据wsdl文件生成webservice客户端-图例.pdf
根据wsdl文件生成的接口类,请帮助分析
NULL 博文链接:https://wjch-111.iteye.com/blog/2375406