SOAP错误:未将对象设置为对象的实例

时间:2010-10-25 11:29:22

标签: php soap

我在这里发现了这个问题: PHP Soap Issue: Server was unable to process request. ---> Object reference not set to an instance of an object

我有类似的问题,只有WSDL是私有的,所以我想我会尝试使用基本的时区SOAP客户端。

另一个问题的解决方案不可能与私有WSDL一起使用。

$response = $client->getTimeZoneTime(array('timezone'=>'ZULU'));

我真正需要的是一种获取多维PHP数组并将其放入SOAP格式的XML文档中的方法,不会让它变得疯狂并产生类似的东西,例如: -

<key>GetTimeZoneTime</key>
<item>ZULU</item>

这是我的PHP:

try {

    $WSDL = 'http://www.nanonull.com/TimeService/TimeService.asmx?WSDL';
    $client = new SoapClient($WSDL, 
        array(
            "trace"      => 1,
            "exceptions" => 1,
            "soap_version" => SOAP_1_1
            ));

    $xml = '<GetTimeZoneTime><timezone>ZULU</timezone></GetTimeZoneTime>';

    $xmlvar = new SoapVar(
                $xml,
                XSD_ANYXML
    );

    $response = $client->getTimeZoneTime($xmlvar);

    echo "<pre>\n";
    echo "Request :\n".htmlspecialchars($client->__getLastRequest()) ."\n";
    echo "Response:\n".htmlspecialchars($client->__getLastResponse())."\n";
    echo "</pre>"; 

} catch (SoapFault $exception) {
    echo "<pre>\n";
    echo "Request :\n".htmlspecialchars($client->__getLastRequest()) ."\n";
    echo "Response:\n".htmlspecialchars($client->__getLastResponse())."\n";
    echo $exception;
    echo "</pre>";
}

这是它产生的请求:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.Nanonull.com/TimeService/">
    <SOAP-ENV:Body>
        <GetTimeZoneTime>
            <timezone>ZULU</timezone>
        </GetTimeZoneTime>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

SOAP Fault是:

Server was unable to process request. ---> Object reference not set to an instance of an object.

将多维PHP数组转换为适当的SOAP请求格式的正确方法是什么?

返回的SOAP错误究竟意味着什么?

编辑:在其他地方搜索之后,我想我会尝试创建一个PHP类来镜像服务器上的变量。这也不起作用。

class TimeZone {
    public function __construct ()
    {
        $this->timezone = 'ZULU';
    }
}

$WSDL = 'http://www.nanonull.com/TimeService/TimeService.asmx?WSDL';
$client = new SoapClient($WSDL, 
    array(
        "trace"      => 1,
        "exceptions" => 1,
        "soap_version" => SOAP_1_1
        ));

$xmlvar = new SoapVar(new TimeZone(), SOAP_ENC_OBJECT, "TimeZone");

$response = $client->getTimeZoneTime($xmlvar);

1 个答案:

答案 0 :(得分:1)

对于Timezone,添加classmap参数使其工作:

$client = new SoapClient($WSDL, 
        array(
            "trace"      => 1,
            "exceptions" => 1,
            "soap_version" => SOAP_1_1,
            "classmap" => array('timezone' => 'TimeZone')
            ));

$obj = new TimeZone();
$response = $client->getTimeZoneTime($obj);
echo "<h1>".$response->getTimeZoneTimeResult."</h1>";

对于我遇到的主要问题,它需要一个新问题。

我可能错了,但我收集错误信息的含义是双重的:

  1. 传入soap调用的对象可能根本不是对象。
  2. 传入soap调用的对象可能是一个对象,但是如果它的所有属性与服务器期望的属性不匹配,它将返回该错误。