SOAP error: object not installed in object instance

I found this question here: PHP soap problem: server could not process the request. ---> The reference to the object is not installed in the instance of the object

I have a similar problem, only WSDL is private, so I decided that I would try to use the base client of the time zone SOAP client.

The solution in another question is not possible for use with a private WSDL.

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

Indeed, I need a way to make a multidimensional PHP array and put it in an XML document generated by SOAP, without its craziness and creating things like, for example, for this: -

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

Here is my 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>";
}

This is the request he makes:

<?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>

And SOAP error:

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

What is the right way to turn a multidimensional PHP array into the appropriate format for a SOAP request?

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);
+3
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

Source: https://habr.com/ru/post/1771289/


All Articles