• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

如何使用PHP实现一个WebService_MySQL

mysql 搞代码 4年前 (2022-01-09) 16次浏览 已收录 0个评论

WSDL

WSDL(网络服务描述语言,Web Services Description Language)是一门基于 XML 的语言,用于描述 Web Services 以及如何对它们进行访问。这种文档可描述某个 Web service。它可规定服务的位置,以及此服务提供的操作(或方法)。

一个 WSDL 文档的主要结构是类似这样的:

		   definition of types........			   definition of a message....			   definition of a port.......			   definition of a binding....	

WSDL 文档可包含其它的元素,比如 extension 元素,以及一个 service 元素,此元素可把若干个 web services 的定义组合在一个单一的 WSDL 文档中。

PHP生成WSDL

类代码(SoapDiscovery.class.php):

<?phpclass 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.= "service_name" targetNamespace="urn:$this->service_name" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tn<b>本文来源gao@!dai!ma.com搞$$代^@码5网@</b>s="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.= "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 = 'service_name.'Port">';        $bindingWSDL = 'service_name.'Binding" type="tns:'.$this->service_name."Port">nn";        $serviceWSDL = 'service_name."">nnservice_name.'Port" binding="tns:'.$this->service_name."Binding">nnn";        $messageWSDL = '';        foreach ($methods as $method) {            if ($method->isPublic() && !$method->isConstructor()) {                $portTypeWSDL.= 'getName()."">n".'getName()."Request" />ngetName()."Response" />nn";                $bindingWSDL.= 'getName()."">n".'service_name.'#'.$this->class_name.'#'.$method->getName()."" />nservice_name" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />nnnservice_name" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />nnn";                $messageWSDL.= 'getName()."Request">n";                $parameters = $method->getParameters();                foreach ($parameters as $parameter) {                    $messageWSDL.= 'getName()."" type="xsd:string" />n";                }                $messageWSDL.= "n";                $messageWSDL.= 'getName()."Response">n";                $messageWSDL.= 'getName()."" type="xsd:string" />n";                $messageWSDL.= "n";            }        }        $portTypeWSDL.= "n";        $bindingWSDL.= "n";        return sprintf('%s%s%s%s%s%s', $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, '');    }        /**     * SoapDiscovery::getDiscovery() Returns discovery of WSDL.     *      * @return string     **/    public function getDiscovery() {        return "<?xml version="1.0" ?>nnn";    }} ?>

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:如何使用PHP实现一个WebService_MySQL
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址