SOAP Multi-Namespace Request

So I’m new to using SoapClient.
It’s… not very well documented, really.

But still, here’s what i’ve managed to do.

I have a WSDL that defines available requests; For simplicity’s sake, lets assume there are two: Login and Get.

Instantiate a SoapClient…check.

$client = new SoapClient($wsdlurl);

(I’m not particularly focussed on Options atm.)

Create a request for Login. Now, I know that my Request eventually needs to look like: (Roughly)

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope">

<soap:Body xmlns:ns1="http://www.example.org/a_valid_endpoint">
    <ns1:username>Quack</ns1:username>
    <ns1:pwd>Moo</ns1:pwd>
</soap:Body>

</soap:Envelope>

So, I do:

$res = $client->Login(array('username' => 'Quack', 'pwd' => 'Moo'));

And all works fine.
When it comes to my Get, however, the result needs to look like: (Simplified)

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope">

<soap:Body xmlns:ns1="http://www.example.org/a_valid_schema" xmlns:ns2="http://a.different/schema">
    <ns1:objectType>Quacker</ns1:objectType>
    <ns1:object>
        <ns2:id>10</ns2:id>
        <ns2:name>A Thing</ns2:name>
    </ns1:object>
</soap:Body>

I tried:

$res = $client->Get(array('objectType' => 'Quacker', 'object' => array('id' => 10, 'name' => 'Moo')));

but Wireshark shows that the POST in this case sent:

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope">
    <soap:Body xmlns:ns1="http://www.example.org/a_valid_schema">
    <ns1:objectType>Quacker</ns1:objectType>
    <ns1:object />
</soap:Body>

So i’m a little confused.

So Update #1: I’ve… sort of got it working. But not really.
Defining my array as a SoapVar… SORT of works around the problem:

$moid = new SoapVar(array('id' => "10", 'name' => "Moo"), SOAP_ENC_OBJECT, NULL, "http://a/schema");
$res = $client->Get(array('objectType' => "Quacker@http://a/schema", 'object' => $moid));

But this doesnt apply the namespace, and instead comes out with something along the lines of.

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope">

<soap:Body xmlns:ns1="http://www.example.org/a_valid_schema">
<ns1:Get>
    <ns1:objectType>Quacker@http://a/schema</ns1:objectType>
    <ns1:object>
        <id>10</id>
        <name>A Thing</name>
    </ns1:object>
</ns1:Get>
</soap:Body>

If I define a name (objectName) instead of NULL, i get:

<?xml version="1.0"?>
<soap:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope"
 xmlns:ns1="http://www.example.org/a_valid_schema"
 xmlns:ns2="http://a/schema"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<soap:Body xmlns:ns1="http://www.example.org/a_valid_schema">
<ns1:Get>
    <ns1:objectType>Quacker@http://a/schema</ns1:objectType>
    <ns1:object xsi:type="ns2:objectName">
        <id>10</id>
        <name>A Thing</name>
    </ns1:object>
</ns1:Get>
</soap:Body>

Still trying to figure out how to make it work properly; the server receiving the requests doesn’t seem to be fussy about the namespaces, so i suppose this is mostly me being picky.

So what i ended up having to do was:

  array_walk($array,'soapvar',$schema);

function soapvar(&$item,$key,$schema) {
  $item = new SoapVar($item, XSD_STRING,NULL,NULL,$key,$schema);
}  

and then use $array in my original Get request. Seems clunky, but… whatever makes it work, i suppose.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.