PHP SOAP with .NET service "Object reference not set to an instance of an object"

4 views
Skip to first unread message

Vlad

unread,
May 2, 2008, 3:32:55 PM5/2/08
to php
Hello,
HELP!!!

I am using PHP built-in SOAP Extension.

I get "Object reference not set to an instance of an object" SoapFault
exception when passing an object (a PHP class) to a .NET webservice
from a PHP soapclient. When I retrieve data from the service I get no
errors.

In fact, the object does not even appear in the SOAP envelope, ONLY
it's fields appear.
Has anybody had this problem?

Here is how I do it:
---------------------------------------------------------------------------------------------------------------------------------
class SpParent {
public $ParentID;
public $ParentType;

}

$params = null;
settype($params, 'object'); # this may not even be needed

# Create new instance of class and assign the values
$params = new SpParent;
$params->ParentID = 10;
$params->ParentType = 'primary';

### Create new instance of SOAP client
# NOTE: map 'Parent' to 'SpParent', because the class is called
'Parent' on the server,
# and PHP does not allow to create a class called 'Parent' (reserved
word)
$client = new SoapClient('http://path/to/some/wsdl', array( 'classmap'
=> array ("Parent" => "SpParent"),

'trace' => true,

'exceptions' => true);

### Call function 'AddParent' and pass the object
$AddParentResponse = $client->__soapCall('AddParent', array($params));

---------------------------------------------------------------------------------------------------------------------------------
HERE IS HOW THE SOAP ENVELOPE LOOKS LIKE:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/
envelope/"
xmlns:ns1="http://path/to/some/
namespace">
<SOAP-ENV:Body>
<ns1:AddParent>
<ns1:ParentID>10</ns1:ParentID>
<ns1:ParentType>primary</ns1:ParentType>
</ns1:AddParent>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Now according to the webservice sample request the ParentID and
ParentType elements should be enclosed within a 'Parent' element.
---------------------------------------------------------------------------------------------------------------------------------
HERE IS HOW THE SOAP ENVELOPE SHOULD LOOK LIKE:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/
envelope/"
xmlns:ns1="http://path/to/some/
namespace">
<SOAP-ENV:Body>
<ns1:AddParent>
<ns1:Parent>
<ns1:ParentID>10</ns1:ParentID>
<ns1:ParentType>primary</ns1:ParentType>
</ns1:Parent>
</ns1:AddParent>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
---------------------------------------------------------------------------------------------------------------------------------
I used nusoap, PEAR SOAP, but these are no good as well, if not worse.
I would greatly appreciate any help! This is driving me nuts already.

-vlad
Reply all
Reply to author
Forward
0 new messages