Prefixing arguments with namespaces (without WSDL)
| From: | David Sklar | Date: | Wed, 17 Dec 2003 18:51:19 +0000 |
| Subject: | Prefixing arguments with namespaces (without WSDL) | ||
| Groups: | php.soap | ||
| Request: | Send a blank email to php-soap+get-1232@lists.php.net to get a copy of this message | ||
I am using PEAR SOAP 0.8RC2.
The following WSDL-based code works great (I get a response from the server
indicating that yes, Lorne Greene is dead.)
$wsdl = new
SOAP_WSDL('http://www.abundanttech.com/webservices/deadoralive/deadoralive.w
sdl');
$client = $wsdl->getProxy();
$ret = $client->getDeadOrAlive('Lorne Greene');
The following non-WSDL-based code doesn't work (I get back an empty
envelope)
$client = new
SOAP_Client('http://www.abundanttech.com/webservices/deadoralive/deadoralive
.asmx');
$options = array('namespace' =>
'http://www.abundanttech.com/webservices/deadoralive',
'soapaction' =>
'http://www.abundanttech.com/webservices/deadoralive/getDeadOrAlive');
$args = array('sFullName' => 'Lorne Greene');
$ret = $client->call('getDeadOrAlive', $args, $options);
Both the WSDL and non-WSDL versions include the app-specific namespace in
the envelope with an attribute like this:
xmlns:ns4="http://www.abundanttech.com/webservices/deadoralive"
inside the <SOAP-ENV:Envelope> tag.
The crucial difference seems to be that the WSDL version correctly includes
a namespace for the argument to the method, while the non-WSDL version
doesn't. The WSDL version sends this as the body of the envelope:
<SOAP-ENV:Body>
<ns4:getDeadOrAlive>
<ns4:sFullName>Lorne Greene</ns4:sFullName></ns4:getDeadOrAlive>
</SOAP-ENV:Body>
The non-WSDL version sends this body:
<SOAP-ENV:Body>
<ns4:getDeadOrAlive>
<sFullName xsi:type="xsd:string">Lorne
Greene</sFullName></ns4:getDeadOrAlive>
</SOAP-ENV:Body>
If I specify "ns4:sFullName" as the name of the argument instead of just
"sFullName" in the non-WSDL version, then I get back a successful response
just like in the WSDL version. But I only know that ns4 is the right
namespace from examining the wire output from unsucessful requests, so this
isn't really a scalable or pretty way to do it.
In circumstances where I can't use WSDL, how can I make sure that the
correct namespace prefix is prepended to my argument names?
Thanks,
David