We are in the process of converting a RPC/encoded webservice to document/literal/wrapped. The WSDL (using nusoap) is already rewritten to use the new format.
I use PHP SoapClient like this:
new SoapClient($wsdlUrl, array(
'cache_wsdl' => WSDL_CACHE_NONE,
'trace' => true,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
));
The relevant WSDL parts looks like this, (should be following the WS-I Basic Profile):
<xsd:complexType name="messages">
<xsd:sequence>
<xsd:element name="item" type="xsd:string" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="some_functionResponseType">
<xsd:all>
<xsd:element name="return" type="tns:messages" form="unqualified"/>
</xsd:all>
</xsd:complexType>
<message name="some_functionResponse">
<part name="parameters" element="tns:some_functionResponseType"/>
</message>
<operation name="some_function">
<input message="tns:some_functionRequest"/>
<output message="tns:some_functionResponse"/>
</operation>
When I submit my request, the XML response is like this:
<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<some_functionResponse xmlns="urn:toets_nl_wsdl">
<messages xmlns="">
<item>foo</item>
<item>bar</item>
</messages>
</some_functionResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
When I dump the result object in PHP, it looks like this:
stdClass Object
(
[messages] => stdClass Object
(
[item] => Array // <-- here
(
[0] => foo
[1] => bar
)
)
)
Why is there an extra element "item" in the result tree? This wasn't there when we were still using RPC/encoded.
Is there a way to remove that element when processing the response?
Your WSDL clearly states that there is an item with unlimited number of occurrences, that contains strings (also known as an array). So PHP just presents to you the structure as described in the WSDL, and as returned by the server.
I cannot see that there is anything wrong. Don't expect Soap to be the same as RPC just because it does the same. If you don't want that item element there, change the WSDL and the service - but this might be more difficult than to fit your PHP client code to the new data structure.
You even used SOAP_SINGLE_ELEMENT_ARRAYS, which is a good thing to avoid checking if the element really was an array or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With