【问题标题】:Problem with creating Web Service (reflection error)创建 Web 服务时出现问题(反射错误)
【发布时间】:2011-07-18 22:11:16
【问题描述】:

我只是想用 PHP 创建我的第一个基于 SOAP/WSDL 的 Web 服务。我决定使用 PEAR 的 Services_Webservice 包。这就是我为了执行一些测试而编写的代码(文件 ws.php):

<?php
ini_set("include_path", '/home/maciek/php:' . ini_get("include_path")  );
ini_set("soap.wsdl_cache_enabled", "0");

require_once 'Services/Webservice.php';

class Box
{
    /**
    * @var int
    */
    public $length = 1;
    /**
    * @var int
    */
    public $width = 2;
    /**
    * @var int
    */
    public $height = 3;
}

class NamedBox extends Box
{
    /**
    * @var string
    */
    public $name = "ABC";
}

$Boxes[1] = new Box();
$Boxes[2] = new Box();

class ws extends Services_Webservice
{
    /**
    * Some data
    */
    private $someData = array (
            'A' => array('B', 'C'),
            'X' => array('Y', 'Z')
            );

    /**
    * Getting some data
    * @param string
    * @return string[]
    */
    public function getsomeData($key)
    {
        $result = array();
        if (isset($this->someData[$key]))
        {
            $result = $this->someData[$key];
        }
        return $result;
    }

    /**
    * Getting Boxes
    * @return Box[]
    */
    public function getBoxes()
    {
        return $Boxes;
    }

    /**
    * Getting NamedBox
    * @return NamedBox
    */
    public function getNamedBox()
    {
        return new NamedBox();
    }   
}

$options = array('uri' => 'ws', 'encoding' => SOAP_ENCODED);

$service = new ws('ws', 'description', $options);

$service->handle();
?>

接下来我要做的是获取 WSDL 文件。根据 PEAR 的文档,我需要将 ?wsdl 字符串添加到我的文件的 URL。问题很奇怪——我的服务只工作一次!第一次服务调用后一切正常,我的浏览器中可以看到 WSDL 文件。但接下来(在网络浏览器中刷新页面,甚至在另一个网络浏览器中)调用失败......我收到两条错误消息:

1) 警告:strpos() [function.strpos]:第 518 行 /home/maciek/php/Services/Webservice.php 中的字符串中不包含偏移量

2) 致命错误:/home/maciek/php/Services/Webservice.php:542 中未捕获的异常“ReflectionException”和消息“类不存在”堆栈跟踪:#0 /home/maciek/php/Services/Webservice.php(542 ): ReflectionClass->__construct('') #1 /home/maciek/php/Services/Webservice.php(420): Services_Webservice->classMethodsIntoStruct() #2 /home/maciek/php/Services/Webservice.php(212 ): Services_Webservice->intoStruct() #3 /home/maciek/public_html/noticeboard/boxes/ws.php(82): Services_Webservice->handle() #4 {main} 抛出 /home/maciek/php/Services/第 542 行的 webservice.php

试图找出我注意到的第二个问题的目的是什么,在 PEAR 的代码(Webservice.php 文件)中,一个空字符串被放入 ReflectionClass 的构造函数(但不是在第一次服务调用中!)。

我真的不知道为什么会这样。我试图放置一些回显指令来打印有用的消息,但我没有找到解决方案。最奇怪的是,在第一次成功呼叫后的几个小时内,我的服务又开始工作了——而且只有一次呼叫。此外,在本地主机上我没有问题......你能帮帮我吗?

有用的数据: 阿帕奇 2.2.17, PHP 5.2.12, PEAR Services_Webservice 0.5.1(代码在下面的 542 行左右):

        for ($i = 0; $i < count($params); ++$i) {
            $_class = $params[$i]->getClass();
            $_type  = ($_class) ? $_class->getName() : $param[1][$i];

            $_cleanType = str_replace('[]', '', $_type, $_length);
            $_typens    = str_repeat('ArrayOf', $_length);

            $this->wsdlStruct[$this->classname]['method'][$method->getName()]['var'][$i]['name'] =
                    $params[$i]->getName();
            $this->wsdlStruct[$this->classname]['method'][$method->getName()]['var'][$i]['wsdltype'] =
                    $_typens . $_cleanType;
            $this->wsdlStruct[$this->classname]['method'][$method->getName()]['var'][$i]['type'] =
                    $_cleanType;
            $this->wsdlStruct[$this->classname]['method'][$method->getName()]['var'][$i]['length'] =
                    $_length;
            $this->wsdlStruct[$this->classname]['method'][$method->getName()]['var'][$i]['array'] =
                    ($_length > 0 && in_array($_cleanType, $this->simpleTypes))
                    ? true : false;
            $this->wsdlStruct[$this->classname]['method'][$method->getName()]['var'][$i]['class'] =
                    (!in_array($_cleanType, $this->simpleTypes) && new ReflectionClass($_cleanType))
                    ? true : false; //THAT WAS 542 line
            $this->wsdlStruct[$this->classname]['method'][$method->getName()]['var'][$i]['param'] = true;
        }

那是518行

$docComments_Description = trim(substr($_docComments_Description, strpos($_docComments_Description, '*') + 1, strpos($_docComments_Description, '*', 1) - 1));

【问题讨论】:

    标签: php web-services apache pear


    【解决方案1】:

    请在梨包网站上打开错误报告。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-30
      • 1970-01-01
      • 1970-01-01
      • 2020-09-02
      • 1970-01-01
      • 2018-01-24
      • 1970-01-01
      • 2013-12-13
      相关资源
      最近更新 更多