tags:

views:

37

answers:

1

I found this question on here: http://stackoverflow.com/questions/927566/php-soap-issue-server-was-unable-to-process-request-object-reference-not-s

I have a similar issue, only the WSDL is private, so I figured I'd try and get a basic timezone SOAP Client working.

The solution in the other question isn't possible for me to use with the private WSDL.

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

Really what I need is a way of taking a multidimensional PHP array and putting it into the SOAP formed XML document, without it going crazy and producing stuff like, for this example, this:-

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

Here's 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 it produces:

<?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/"&gt;
    <SOAP-ENV:Body>
        <GetTimeZoneTime>
            <timezone>ZULU</timezone>
        </GetTimeZoneTime>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

And the SOAP Fault is:

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

What's the correct way of turning a multidimensional PHP array into the appropriate format for a SOAP request?

What does the SOAP fault returned actually mean?

Edit: After some searching around elsewhere I thought I'd try the approach of creating a PHP class to mirror the variables on the server. This doesn't work either.

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  A: 

For the Timezone one, adding the classmap parameter made it work:

$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>";

For the main problem I'm having, it warrants a new question.

I may be wrong, but I gather the meaning of the error message to be twofold:

  1. The object passed into the soap call may not be an object at all.
  2. The object passed into the soap call may be an object, but if all of its attributes do not match what the server expects it will return that error.
bcmcfc