SoapDiscovery.class.php【PHP自动生成WSDL】

SoapDiscovery.class.php 源码如下:

============================================================

  1 <?php
  2
  3 /**
  4  * Copyright (c) 2005, Braulio Jos?Solano Rojas
  5  * All rights reserved.
  6  *
  7  * Redistribution and use in source and binary forms, with or without modification, are
  8  * permitted provided that the following conditions are met:
  9  *
 10  *     Redistributions of source code must retain the above copyright notice, this list of
 11  *     conditions and the following disclaimer.
 12  *     Redistributions in binary form must reproduce the above copyright notice, this list of
 13  *     conditions and the following disclaimer in the documentation and/or other materials
 14  *     provided with the distribution.
 15  *     Neither the name of the Solsoft de Costa Rica S.A. nor the names of its contributors may
 16  *     be used to endorse or promote products derived from this software without specific
 17  *     prior written permission.
 18  *
 19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 20  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 21  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 22  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 23  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 30  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 31  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  *
 34  * @version $Id$
 35  * @copyright 2005
 36  */
 37
 38 /**
 39  * SoapDiscovery Class that provides Web Service Definition Language (WSDL).
 40  *
 41  * @package SoapDiscovery
 42  * @author Braulio Jos?Solano Rojas
 43  * @copyright Copyright (c) 2005 Braulio Jos?Solano Rojas
 44  * @version $Id$
 45  * @access public
 46  **/
 47 class SoapDiscovery {
 48     private $class_name = ‘‘;
 49     private $service_name = ‘‘;
 50
 51     /**
 52      * SoapDiscovery::__construct() SoapDiscovery class Constructor.
 53      *
 54      * @param string $class_name
 55      * @param string $service_name
 56      **/
 57     public function __construct($class_name = ‘‘, $service_name = ‘‘) {
 58         $this->class_name = $class_name;
 59         $this->service_name = $service_name;
 60     }
 61
 62     /**
 63      * SoapDiscovery::getWSDL() Returns the WSDL of a class if the class is instantiable.
 64      *
 65      * @return string
 66      **/
 67     public function getWSDL() {
 68         if (empty($this->service_name)) {
 69             throw new Exception(‘No service name.‘);
 70         }
 71         $headerWSDL = "<?xml version=\"1.0\" ?>\n";
 72         $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/2001/XMLSchema\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns=\"http://schemas.xmlsoap.org/wsdl/\">\n";
 73         $headerWSDL.= "<types xmlns=\"http://schemas.xmlsoap.org/wsdl/\" />\n";
 74
 75         if (empty($this->class_name)) {
 76             throw new Exception(‘No class name.‘);
 77         }
 78
 79         $class = new ReflectionClass($this->class_name);
 80
 81         if (!$class->isInstantiable()) {
 82             throw new Exception(‘Class is not instantiable.‘);
 83         }
 84
 85         $methods = $class->getMethods();
 86
 87         $portTypeWSDL = ‘<portType name="‘.$this->service_name.‘Port">‘;
 88         $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";
 89         $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";
 90         $messageWSDL = ‘‘;
 91         foreach ($methods as $method) {
 92             if ($method->isPublic() && !$method->isConstructor()) {
 93                 $portTypeWSDL.= ‘<operation name="‘.$method->getName()."\">\n".‘<input message="tns:‘.$method->getName()."Request\" />\n<output message=\"tns:".$method->getName()."Response\" />\n</operation>\n";
 94                 $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";
 95                 $messageWSDL.= ‘<message name="‘.$method->getName()."Request\">\n";
 96                 $parameters = $method->getParameters();
 97                 foreach ($parameters as $parameter) {
 98                     $messageWSDL.= ‘<part name="‘.$parameter->getName()."\" type=\"xsd:string\" />\n";
 99                 }
100                 $messageWSDL.= "</message>\n";
101                 $messageWSDL.= ‘<message name="‘.$method->getName()."Response\">\n";
102                 $messageWSDL.= ‘<part name="‘.$method->getName()."\" type=\"xsd:string\" />\n";
103                 $messageWSDL.= "</message>\n";
104             }
105         }
106         $portTypeWSDL.= "</portType>\n";
107         $bindingWSDL.= "</binding>\n";
108         //return sprintf(‘%s%s%s%s%s%s‘, $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, ‘</definitions>‘);
109
110         $fso = fopen($this->class_name . ".wsdl", "w");
111         fwrite($fso, sprintf(‘%s%s%s%s%s%s‘, $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, ‘</definitions>‘));
112     }
113
114     /**
115      * SoapDiscovery::getDiscovery() Returns discovery of WSDL.
116      *
117      * @return string
118      **/
119     public function getDiscovery() {
120         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>";
121     }
122 }
123
124 ?>
时间: 2024-11-09 10:14:11

SoapDiscovery.class.php【PHP自动生成WSDL】的相关文章

php学习之道:php中soap的使用实例以及生成WSDL文件,提供自动生成WSDL文件的类库——SoapDiscovery.class.php类

1. web service普及: Webservice soap wsdl区别之个人见解 Web Service实现业务诉求:  Web Service是真正"办事"的那个,提供一种办事接口的统称. WSDL提供"能办的事的文档说明":  对要提供的服务的一种描述格式.我想帮你的忙,但是我要告诉你我都能干什么,以及干这些事情需要的参数类型. SOAP提供"请求"的规范:  向服务接口传递请求的格式,包括方法和参数等.你想让人家办事,总得告诉人家

java之wsdl自动生成WebService客户端

在web项目中调用webservice接口,以及创建自己的webservice服务端 由于甲方的服务器并不在外网,编码环境是不能直接访问对方的webservice接口的,所以需要把wsdl文件下载到本地,在通过工具生成代理类. 用java的JDK自带命令wsimport -s . xxx.wsdl生成代理类 其中-s表示生成源代码,不指定的话只会生成.calss字节码文件 中间的点"."表示在当前路径 后面空格接上本地的wsdl文件或者URL,例如http://www.xxx.com/

eclipse根据.wsdl文件自动生成webservice的调用客户端

1.工具:eclipse3.3或者是带有webservice插件的eclipse 2. 首先用浏览器访问webservice的站点,接着保存打开的页面,后缀为.wsdl. 3.把保存好的文件拷入eclipse的工程中. 4.eclipse:file----new---other----webservice----web service client,选择之前拷贝到eclipse中的.wsdl文件,点击finish. 这样eclipse就帮我们自动生成了web service的客户端,接下来只需在

基于wsdl的测试数据自动生成技术

1. 大概思路 ①首先导入wsdl文档,进行分析,生成wsdl树或者什么表现形式,得到要输入数据的类型以及约束,然后针对类型约束进行相应的测试数据的生成(生成原则如下图1). 模型生成步骤: 为输入数据建立模型主要有以下几步: 第一步:以一个复杂数据类型的名字作为初始节点(根节点). 第二步:如果根节点的某个子元素仍然是复杂数据类型,那么生成一个该子复杂类型的节点,另外一条以该子复杂类型名为名字的一条边,用以指向该子复杂类型的节点. 第三步:如果根节点的某个子元素是一个基本类型(一种简单数据类型

API的文档自动生成——基于CDIF的SOA基本能力

当前,作为大部分移动app和云服务后台之间的标准连接方式,REST API已经得到了绝大部分开发者的认可和广泛的应用.近年来,在新兴API经济模式逐渐兴起,许多厂商纷纷将自己的后台业务能力作为REST API开放出来,给更广泛的第三方开发者使用. 但是,管理REST API并非是一件容易的工作.由于缺乏有效的接口数据schema约束,加上设计REST API时resource endpoint的安排,以及发送http请求的方式又都五花八门,REST API开发完成后,大多数情况下API开发者仍然

关于 wsdl2Java 自动生成客户端调取webservice接口

webservice地址:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl wsdl2Java 自动生成类名: 客户端调用:

PHP webserver 之 soap 生成wsdl文件

<?php /** * Copyright (c) 2005, 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 o

使用Eclipse自带的Axis1插件生成WSDL文件

首先创建一个web工程,创建过程如下: 如果选择Apache Tomcat v5.5,Dynamic web module version最高只能选择2.4,填写完成后点击“下一步”: 填写默认输出文件夹,填写完成后点击“下一步”: 填写根目录,填写完成后点击“完成”: 工程创建完成后,编写服务接口: [java] view plain copy package com.sean.ws; public interface MathIntf { public int plus(int a, int

使用MyBatis Generator自动生成实体、mapper和dao层

通过MyBatis Generator可以自动生成实体.mapper和dao层,记录一下怎么用的. 主要步骤: 关于mybatis从数据库反向生成实体.DAO.mapper: 参考文章:http://www.cnblogs.com/wangkeai/p/6934683.html第一种方式:main方法运行(推荐) 1.在pom.xml中加入插件依赖: 2.写mbgConfiguration.xml文件,jdbc.properties文件 3.写/SSM/src/main/java/main/Ge