在PHP中利用wsdl创建标准webservice
参照整理:
http://bbs.php100.com/read-htm-tid-95228.html http://www.ieliwb.com/wsdl-create-soapdiscovery/说明:
- 非标准的webservice,可能只能PHP才能访问
- 标准的webservice,就必须要使用wsdl
在这里我只介绍标准的webservice
一、 创建WSDL
1。网上下载SoapDiscovery.class.php类
2。修改SoapDiscovery.class.php的公共方法getWsdl(),让其自动生成wsdl文件(注意存放路径),这里只是创建一个wsdl模型

1 //return sprintf('%s%s%s%s%s%s', $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, '</definitions>');
2 //生成wsdl文件,将上面的return注释
3 $fso = fopen($this->class_name . ".wsdl" , "w");
4 fwrite($fso, sprintf('%s%s%s%s%s%s', $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, '</definitions>'));
5 exit;

3。提供服务的类或者函数

1 //比如我有个类:person,文件名为:person.class.php★,里面有两个方法,一个是say,一个是run。很简单。
2 <?php
3 class person
4 {
5 public function say()
6 {
7 return("i'm speaking.");
8 }
9 public function run()
10 {
11 return("i'm running,don't disturb me please.");
12 }
13 }
14 ?>

4。开始正式生成wsdl:
创建文件server.php。将以下内容拷贝进去,运行即可生成一个person.wsdl文件

1 <?php
2 include("person.class.php");
3 include("SoapDiscovery.class.php");
4 //第一个参数是类名(生成的wsdl文件就是以它来命名的),即person类,第二个参数是服务的名字(这个可以随便写)。
5 $disco = new SoapDiscovery('person','Person');
6 $disco->getWSDL();
7 ?>

5。创建webservice服务端程序
将server.php文件的内容清空,复制以下代码进去:

1 <?php
2 include("person.class.php");
3 $objSoapServer = new SoapServer("person.wsdl");//person.wsdl是刚创建的wsdl文件
4 //$objSoapServer = new SoapServer("server.php?wsdl");//这样也行
5 $objSoapServer->setClass("person");//注册person类的所有方法
6 $objSoapServer->handle();//处理请求
7 ?>

6。创建webservice客户端程序,测试webservice是否有效,文件名是:client.php

<?php
$client = new SoapClient("person.wsdl");
//$client = new SoapClient("server.php?wsdl");//这样也行
echo($client->say());
echo "<br />";
echo($client->run());
echo "<br />";
?>

7。.NET如果要使用的话,你只要提供一个url给他就行了。
获得url的方法:你可以先到person.wsdl文件里面查找<soap:address location="http://xxxxxxxxxxxxxxxxxxxx/server.php" />,这里的url(具体url是根据你的目录确定的)就是你要提供给.NET开发人员使用的。不过别高兴太早,后面要加:“?wsdl”,http://xxxxxxxxxxxxxxxxxxxx/server.php?wsdl这样才是对的,不信你可以将url拷贝到浏览器的地址栏里看下就知道了。
.NET开发人员获得你给他的url之后,就可以在自己的项目里面添加一个服务引用或者web引用了,然后就可以根据提示完成相关操作,对于使用.NET的开发人员来说很简单的。
(1)创建一网站,创建一个web引用,输入url
(2)实力调用

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
sdaf.Solsoft_HelloWorld ddd = new sdaf.Solsoft_HelloWorld();
Label1.Text = ddd.say();
}
}

在PHP中利用wsdl创建标准webservice的更多相关文章
- 解析利用wsdl.exe生成webservice代理类的详解
利用wsdl.exe生成webservice代理类:根据提供的wsdl生成webservice代理类1.开始->程序->Visual Studio 2005 命令提示2.输入如下红色标记部 ...
- SQL中利用脚本创建database mail.
SQL中利用脚本创建database mail 编写人:CC阿爸 2014-6-14 多话不讲,请参考以下脚本 use
- NetBeans中从实体创建Restful webservice工程
分布式系统和移动计算...... 这学期上的课,名字听起来是不是很霸气? 然而 其实就是 restful 和 安卓...... 汗....... 用的IDE还是netBeans, 第一次听说有这个ID ...
- java中利用JFrame创建窗体 【转】
1. 一个简单的swing public class Test(){ public static void main(String[] args){ JFrame frame = new JFrame ...
- Java中利用JFrame创建窗体
1. 一个简单例子: public class Test(){ public static void main(String[] args){ JFrame frame = new JFrame(); ...
- 利用wsdl.exe生成webservice代理类
通常要手动生成WebService代理类需要把一句生成语句,如 wsdl.exe /l:cs /out:D:\Proxy_UpdateService.cs http://localhost:1101 ...
- idea 中利用maven创建java web 项目
转自:http://www.linuxidc.com/Linux/2014-04/99687.htm 本文主要使用图解介绍了使用IntelliJ IDEA 12创建Maven管理的Java Web项目 ...
- elcipse 中利用maven创建web工程
如何创建: http://huxiaoheihei.iteye.com/blog/1766986 遇到的问题: 1: 如果spring MVC配置了 <servlet> <servl ...
- 在Visual Studio中利用NTVS创建Pomelo项目
刚看新闻,才知道微软发布了Node.js Tools for Visual Studio(NTVS),受够了WebStorm输入法Bug的困扰,这下终于可以解脱了.以Pomelo为例,运行命令:pom ...
随机推荐
- crtbegin_dynamic.o: No such file: No such file or directory
/homesec/android2/zhangbin/053work3/hi050src/HiSTBAndroidV400R001C00SPC050B012/prebuilt/linux-x86/to ...
- 02day2
油滴扩展 [问题描述] 在一个长方形框子里,最多有 N(0≤N≤6)个相异的点.在其中任何-个点上放一个很小的油滴,那么这个油滴会一直扩展,直到接触到其他油滴或者框子的边界.必须等一个油滴扩展完毕才能 ...
- <二>面向对象分析之几个关键的概念
一:建模 --->建模,是指通过对[客观事物]建立一种抽象的方法用以表征事物并获得对事物本身的理解.同时把这种理解概念化,将这些逻辑概念组织起来,构成一种对所观察对象的内部结构和工 ...
- Java基础——I/O续
目录 二进制I/O类 文件导航和I/O 二进制I/O类 FileInputStream类和FileOutputStream类 *FileOutputStream(file: File) *FileOu ...
- 强制将IE8设置为IE7兼容模式来解析网页
强制将IE8设置为IE7兼容模式来解析网页 英文原文:http://msdn.microsoft.com/en-us/library/cc288325(VS.85).aspx 文件兼容性用于定义让IE ...
- PostgreSQL 8.4.1
PHP100资讯:PostgreSQL 是一种对象-关系型数据库管理系统(ORDBMS),也是目前功能最强大.特性最丰富和最复杂的自由软件数据库系统.它起源于伯克利(BSD)的数据库研究计划,目前是最 ...
- Android 翻页效果 电子书
转载请注明来自: 5进制空间-android区 相信做电子书的同学,都遇到过翻页动画的需求吧,如果你不满足与点击滑动翻页的话,这边文章应该能够帮助到你. 先上个效果图: 效果还是很不错的,不过与ibo ...
- codeforces 678D Iterated Linear Function 矩阵快速幂
矩阵快速幂的题要多做 由题可得 g[n]=A*g[n-1]+B 所以构造矩阵 { g[n] } = {A B} * { g[n-1]} { 1 } {0 1 ...
- LeetCode题解——Integer to Roman
题目: 将整数转换为罗马数字.罗马数字规则可以参考: 维基百科-罗马数字 解法: 类似于进制转换,从大的基数开始,求整数对基数的商和余,来进行转换. 代码: class Solution { publ ...
- 下破解安装Python开发工具WingIDE4.1
步骤: 1.将系统时间调整到一个月之前,然后执行安装. 可以使用date命令调整系统时间,如:date -s '2012-08-14 10:00:00' 2.安装成功后,打开程序,按照提示信息,申请一 ...