• 使用 PHP SOAP 来创建一个简单的 Web Service。


    访问:

    http://www.debug.com/php-soap-demo.php?client=22

    结果:

    apache:

    <VirtualHost _default_:80>
    DocumentRoot "E:www	estdebug"
    ServerName www.debug.com
    ServerAlias debug.com
      <Directory "E:www	estdebug">
        Options -Indexes +FollowSymLinks +ExecCGI
        AllowOverride All
        Order allow,deny
        Allow from all
        Require all granted
      </Directory>
    </VirtualHost>
    

      

    code:: php-soap-demo.php

    <?php
    
    /*-------------*/
    if(isset($_GET['client'])){//fixme client index -  客户端入口
        try{
            // non-wsdl方式调用web service
            // 创建 SoapClient 对象
            $soap = new SoapClient(null,array('location'=>"http://www.debug.com/php-soap-demo.php",'uri'=>'php-soap-demo.php'));
            // 调用函数
            $result1 = $soap->getName();
            $result2 = $soap->__soapCall("getHost",array());
            echo $result1."<br/>";
            echo $result2;
        } catch(SoapFault $e){
            echo $e->getMessage();
        }catch(Exception $e){
            echo $e->getMessage();
        }
    }
    /*-------------*/
    
    //fixme server index
    
    //request Class
    Class Request
    {
        //base config
        protected $config = [
            'app'=> '徐锅博客!',
            'host'=>'localhost:3038'
        ];
        //construct
        public function __construct($config= [])
        {
            $this->config = array_merge($this->config,$config);
        }
        //get attr config
        public function __get($name){
            return $this->config[$name];
        }
        //soap method
        public function getName()
        {
            return $this->app;
        }
        //soap method
        public function getHost()
        {
            return $this->host;
        }
    }
    
    // Create SoapServer OBJECT
    $server = new SoapServer(null,array("location"=>"http://www.debug.com/php-soap-demo.php","uri"=>"php-soap-demo.php"));
    
    // EXPORT Request 类中的全部函数
    $server->setClass("Request");
    // 处理一个SOAP请求,调用必要的功能,并发送回一个响应。
    $server->handle();
    

      

  • 相关阅读:
    Oracle 创建dblink
    好的博客
    Java项目导出war包 security alert:integrity check error”
    tomcat7.0 处理问题
    项目支持Servlet3.0的新特性
    oracle replace函数
    JavaWeb项目连接Oracle数据库
    LeetCode OJ
    LeetCode OJ
    LeetCode OJ
  • 原文地址:https://www.cnblogs.com/q1104460935/p/10103919.html
Copyright © 2020-2023  润新知