PHP webserver 之 soap 生成wsdl文件
<?php /**
* Copyright (c) , Braulio Jos?Solano Rojas
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
* Neither the name of the Solsoft de Costa Rica S.A. nor the names of its contributors may
* be used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* @version $Id: SoapDiscovery.class.php -- ::21Z ideaa $
* @copyright
*/ /**
* SoapDiscovery Class that provides Web Service Definition Language (WSDL).
*
* @package SoapDiscovery
* @author Braulio Jos?Solano Rojas
* @copyright Copyright (c) Braulio Jos?Solano Rojas
* @version $Id: SoapDiscovery.class.php -- ::21Z ideaa $
* @access public
* */
class SoapDiscovery { private $class_name = '';
private $service_name = ''; /**
* SoapDiscovery::__construct() SoapDiscovery class Constructor.
*
* @param string $class_name
* @param string $service_name
* */
public function __construct($class_name = '', $service_name = '') {
$this->class_name = $class_name;
$this->service_name = $service_name;
} /**
* SoapDiscovery::getWSDL() Returns the WSDL of a class if the class is instantiable.
*
* @return string
* */
public function getWSDL() {
if (empty($this->service_name)) {
throw new Exception('No service name.');
}
$headerWSDL = "<?xml version=\"1.0\" ?>\n";
$headerWSDL.= "<definitions name=\"$this->service_name\" targetNamespace=\"urn:$this->service_name\" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:tns=\"urn:$this->service_name\" xmlns:xsd=\"http://www.w3.org//XMLSchema\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns=\"http://schemas.xmlsoap.org/wsdl/\">\n";
$headerWSDL.= "<types xmlns=\"http://schemas.xmlsoap.org/wsdl/\" />\n"; if (empty($this->class_name)) {
throw new Exception('No class name.');
} $class = new ReflectionClass($this->class_name); if (!$class->isInstantiable()) {
throw new Exception('Class is not instantiable.');
} $methods = $class->getMethods(); $portTypeWSDL = '<portType name="' . $this->service_name . 'Port">';
$bindingWSDL = '<binding name="' . $this->service_name . 'Binding" type="tns:' . $this->service_name . "Port\">\n<soap:binding style=\"rpc\" transport=\"http://schemas.xmlsoap.org/soap/http\" />\n";
$serviceWSDL = '<service name="' . $this->service_name . "\">\n<documentation />\n<port name=\"" . $this->service_name . 'Port" binding="tns:' . $this->service_name . "Binding\"><soap:address location=\"http://" . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['PHP_SELF'] . "\" />\n</port>\n</service>\n";
$messageWSDL = '';
foreach ($methods as $method) {
if ($method->isPublic() && !$method->isConstructor()) {
$portTypeWSDL.= '<operation name="' . $method->getName() . "\">\n" . '<input message="tns:' . $method->getName() . "Request\" />\n<output message=\"tns:" . $method->getName() . "Response\" />\n</operation>\n";
$bindingWSDL.= '<operation name="' . $method->getName() . "\">\n" . '<soap:operation soapAction="urn:' . $this->service_name . '#' . $this->class_name . '#' . $method->getName() . "\" />\n<input><soap:body use=\"encoded\" namespace=\"urn:$this->service_name\" encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" />\n</input>\n<output>\n<soap:body use=\"encoded\" namespace=\"urn:$this->service_name\" encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" />\n</output>\n</operation>\n";
$messageWSDL.= '<message name="' . $method->getName() . "Request\">\n";
$parameters = $method->getParameters();
foreach ($parameters as $parameter) {
$messageWSDL.= '<part name="' . $parameter->getName() . "\" type=\"xsd:string\" />\n";
}
$messageWSDL.= "</message>\n";
$messageWSDL.= '<message name="' . $method->getName() . "Response\">\n";
$messageWSDL.= '<part name="' . $method->getName() . "\" type=\"xsd:string\" />\n";
$messageWSDL.= "</message>\n";
}
}
$portTypeWSDL.= "</portType>\n";
$bindingWSDL.= "</binding>\n";
//return sprintf('%s%s%s%s%s%s', $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, '</definitions>');
//生成wsdl文件,将上面的return注释
$fso = fopen($this->class_name . ".wsdl", "w");
fwrite($fso, sprintf('%s%s%s%s%s%s', $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, '</definitions>'));
} /**
* SoapDiscovery::getDiscovery() Returns discovery of WSDL.
*
* @return string
* */
public function getDiscovery() {
return "<?xml version=\"1.0\" ?>\n<disco:discovery xmlns:disco=\"http://schemas.xmlsoap.org/disco/\" xmlns:scl=\"http://schemas.xmlsoap.org/disco/scl/\">\n<scl:contractRef ref=\"http://" . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['PHP_SELF'] . "?wsdl\" />\n</disco:discovery>";
} } ?>
PHP webserver 之 soap 生成wsdl文件的更多相关文章
- php中soap的使用实例以及生成WSDL文件,提供自动生成WSDL文件的类库——SoapDiscovery.class.php类
1. web service普及: Webservice soap wsdl区别之个人见解 Web Service实现业务诉求: Web Service是真正“办事”的那个,提供一种办事接口的统称. ...
- PHP soap Web Service 使用SoapDiscovery.class.php 生成wsdl文件
PHP soap web service 使用wsdl文件 demo: ============================================================== 服 ...
- php学习之道:php中soap的使用实例以及生成WSDL文件,提供自己主动生成WSDL文件的类库——SoapDiscovery.class.php类
1. web service普及: Webservice soap wsdl差别之个人见解 Web Service实现业务诉求: Web Service是真正"办事"的那个,提供 ...
- 使用Eclipse提供的Axis1.x生成WSDL文件以及Server和Client代码
使用Eclipse自带的Axis 1.x来创建一个web service应用的服务端和客户端 Axis 是SOAP WebService协议实现,SOAP实质上是一个基于HTTP POST的请求,以X ...
- webservice 服务端例子+客户端例子+CXF整合spring服务端测试+生成wsdl文件 +cxf客户端代码自动生成
首先到CXF官网及spring官网下载相关jar架包,这个不多说.webservice是干嘛用的也不多说. 入门例子 模拟新增一个用户,并返回新增结果,成功还是失败. 大概的目录如上,很简单. Res ...
- 使用Eclipse自带的Axis1插件生成WSDL文件
首先创建一个web工程,创建过程如下: 如果选择Apache Tomcat v5.5,Dynamic web module version最高只能选择2.4,填写完成后点击“下一步”: 填写默认输出文 ...
- php 使用zendstudio 生成webservice文件 wsdl
首先新建一个项目 在项目中新建下面这些文件 php类文件 test.php <?php class test { public function __construct() { } public ...
- VS2010 根据WSDL文件(java Web Service)生成.cs文件
我们添加webService引用,一般是通过 添加服务引用完成的,其实 添加服务引用 在背后为我们生成了代理类. 我们手动生成代理类方法: 1.通过java Web Service,生成wsdl文件: ...
- 根据werservice代码用CXF生成WSDL
原文:http://hongyegu.iteye.com/blog/619147,谢谢! import org.apache.cxf.tools.java2ws.JavaToWS; import ne ...
随机推荐
- https的工作流程
(1)客户端向服务器提出请求,发出SSL握手信号. (2)服务器发出回应,并出示服务器证书(公钥),显示服务器站点身份. (3)客户端验证服务器证书,并生成一个随机的会话密钥,密钥长度达到128位. ...
- IOS微信中看文章跳转页面后点击返回无效
经过查找原因发现,下面两种链接,链接1返回不了,链接2可以返回. 链接1:http://mp.weixin.qq.com/s?__biz=MzA5NDY5MzcyNA==&mid=265089 ...
- 关于VIM统计命令
都是冒号命令哈::%s/./&/gn 统计字符数:%s/\i\+/&/gn 统计单词数:%s/^//n 统计行数:%s/keyword/& ...
- Angular 全局页面切换动画 me-pageloading
最近看了Codrops的一篇文章, 里面讲到了一个页面切换的效果, 详情点击此处. 看了这个效果感觉很赞, 觉得这个效果可以用在angular的页面切换中, 所以将这个效果移植到angular中, 做 ...
- 运用NPOI操作EXCEL
一.引入NPOI程序集 下载地址:http://pan.baidu.com/s/1qWI3Vgo 二.运用NPOI导出成excel文件 protected void btnOutExcel_Click ...
- C#算法基础之递归排序
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 断开SVN连接操作方法
SVN是日常项目管理中经常使用到的工具,然而拷贝备份需要与SVN服务器断开连接,具体操作步骤: 1.在桌面建立一个文本文件,取名为kill-svn-folders.reg(扩展名由txt改为reg), ...
- OC12_自动释放池
// // Dog.h // OC12_自动释放池 // // Created by zhangxueming on 15/6/18. // Copyright (c) 2015年 zhangxuem ...
- 关键字 virtual
Virtual是C++ OO机制中很重要的一个关键字.只要是学过C++的人都知道在类Base中加了Virtual关键字的函数就是虚拟函数(例如函数print),于是在Base的派生类Derived中就 ...
- Linux设备总线
kobject和kset是Linux设备模型中最基本的元素,其中,kset是同种类型kobject对象的集合.每个在内核中注册的kobject对象都对于sysfs文件系统中的一个目录.下面是自己花的一 ...