php中SOAP WebService的wsdl文件生成类

代码如下

 代码如下 复制代码

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/2001/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</soap:address></port>\n</documentation></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</output></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\n<output>\n<soap:body use="\"encoded\"" namespace="\"urn:$this-">service_name\" encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" />\n</soap:body></output>\n</soap:body></soap:operation></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.= "</part></message>\n";
                $messageWSDL.= '<message name="' . $method->getName() . " response\"="">\n";
                $messageWSDL.= '<part name="' . $method->getName() . " \"="" type="\"xsd:string\"">\n";
                $messageWSDL.= "</part></message>\n";
            }
        }
        $portTypeWSDL.= "</soap:binding></binding></porttype>\n";
        $bindingWSDL.= "\n";
        return sprintf('%s%s%s%s%s%s', $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, '</types></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</scl:contractref></disco:discovery>";
    }

}

使用方法

 代码如下 复制代码
$a = new SoapDiscovery();

然后里面的方法与类就可以直接调用了哦。

时间: 2025-01-27 23:43:43

php中SOAP WebService的wsdl文件生成类的相关文章

怎么用axis把wsdl文件生成相应的java类

问题描述 怎么用axis把wsdl文件生成相应的java类,我都已经配置好axis了,发布服务也可以了,就是我现在手里有wsdl文件,想把他生成JAVA类,怎么生成???加我QQ290612821,或者是推荐几个地址,直接告诉我最好啦,嘿嘿 问题补充:我按文章里写的下载了,然后运行后没有在source里生成对应的文件,点完马上就关闭了,是不是命令有问题呀,enet_java 写道 解决方案 引用我按文章里写的下载了,然后运行后没有在source里生成对应的文件,点完马上就关闭了,是不是命令有问题

php静态文件生成类实例分析

 这篇文章主要介绍了php静态文件生成类,以实例形式较为详细的分析了使用php生成静态文件的方法及使用技巧,需要的朋友可以参考下     本文实例讲述了php静态文件生成类.分享给大家供大家参考. 具体实现方法如下: 代码如下: defined('phpjb51') or die(header("http/1.1 403 not forbidden")); class include_createstatic { private $htmlpath = ''; private $pat

php 静态文件生成类

php教程 静态文件生成类 defined('php教程ox') or die(header("http/1.1 403 not forbidden"));                       class include_createstatic             {                                private $htmlpath = '';                private $path = '';              

PHP静态文件生成类实例_php技巧

本文实例讲述了PHP静态文件生成类.分享给大家供大家参考. 具体实现代码如下: 复制代码 代码如下: <?php class CreateHtml { function mkdir( $prefix= 'article' ) { $y = date('Y'); $m = date('m'); $d = date('d'); $p=DIRECTORY_SEPARATOR; $filePath='article'.$p.$y.$p.$m.$p.$d; $a=explode($p,$filePath)

webServices的WSDL文件生成的代理类怎么用?

问题描述 我已经生成的一个代理类,编译为dll,然后在项目中添加的引用,可是我要怎么来调用里面的方法,我一直调用不出来,求大神指导,谢谢各位了 解决方案 解决方案二:既然引用了,这样写不行吗?用New关键字实例化代理类,然后调用代理类的方法呀

怎样根据soap数据写wsdl文件?

问题描述 使用webservice访问的数据如下:请求数据样例:<SOAP-ENV:Body><EAID>EAID</EAID><TranID>TranID</TranID><TranCode>TranCode</TranCode><Password>Password</Password></SOAP-ENV:Body> 返回数据样例:<SOAP-ENV:Body><E

php 静态文件生成类(自家用)

<?phpclass CreateHtml{ function mkdir( $prefix= 'article' ) {  $y = date('Y');  $m = date('m');  $d = date('d');  $p=DIRECTORY_SEPARATOR;  $filePath='article'.$p.$y.$p.$m.$p.$d;  $a=explode($p,$filePath);  foreach ( $a as $dir)  {   $path.=$dir.$p;  

PHP静态文件生成类

<?php class CreateHtml { function mkdir( $prefix= 'article' ) { $y = date('Y'); $m = date('m'); $d = date('d'); $p=DIRECTORY_SEPARATOR; $filePath='article'.$p.$y.$p.$m.$p.$d; $a=explode($p,$filePath); foreach ( $a as $dir) { $path.=$dir.$p; if(!is_di

php生成wsdl文件方法总结

在zend studio9中,与之前版本不一样的是,你需要单独安装wsdl插件,才可以使用,步骤如下: 1.打开zendstudio9,选择help(帮助)->welcome(欢迎 2.在右边的列表中找到WSDL Support,勾选 3.点击Apply changes(应用修改) 4.zde会自动安装,然后提示要重启,点击restart now(现在重新启动) wsdl支持安装完毕,下面我们来生成一个wsdl文件,步骤如下: 1.选择保存wsdl的项目文件夹 2.右键-new(新建)->ot