zoukankan      html  css  js  c++  java
  • 使用 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();
    

      

  • 相关阅读:
    java.lang.NoSuchMethodError:antlr.collections.AST.getLine() I
    T7 java Web day01 标签HTML
    T6 s1 day19
    T5 s5 Day18
    T5 s4 Day 17
    T5 s3 day16
    T5 s2 Day 15
    T5 s1 day14
    T4 S03 day 12
    T4 S01 day1
  • 原文地址:https://www.cnblogs.com/q1104460935/p/10103919.html
Copyright © 2011-2022 走看看