Zend_Soap_Server / PHP SoapServer and the dreaded "objects within array encoded as SOAP-ENC:struct" problem: solved!

NOTE: The information in this post has been superceded by the information in this, more recent post.

So once we got past some basic namespace definition issues, a client using .Net encountered the following problem:

"The specified type was not recognized: name='Struct', namespace='http://schemas.xmlsoap.org/soap/encoding/', at <items xmlns=''>."

The problem was the dreaded PHP5 SOAP encoding issue.

After almost a day of solid searching, the best hint I found was about setting the classmap option of SoapServer. Because the Zend Framework SOAP implementation is really just a wrapper around the standard PHP SOAP functions, setting the classmap was as simple as providing an associative array containing a number of 'ClassName-in-PHP' => 'ClassName-in-WSDL' items.

And voila! Suddenly the offending lines in my response document went from this:

<items enc:itemType="enc:Struct" enc:arraySize="2" xsi:type="enc:Array">
  <item xsi:type="enc:Struct">
    <input xsi:type="xsd:string">Hello World 1!</input>
  </item>
  <item xsi:type="enc:Struct">
    <input xsi:type="xsd:string">Hello World 2!</input>
  </item>
</items>

to this:

<items enc:itemType="enc:Struct" enc:arraySize="2" xsi:type="enc:Array">
  <item xsi:type="ns1:PingRequest">
    <input xsi:type="xsd:string">Hello World 1!</input>
  </item>
  <item xsi:type="ns1:PingRequest">
    <input xsi:type="xsd:string">Hello World 2!</input>
  </item>
</items>

Hopefully this little snippet will save somebody else a day of searching for the solution! As mentioned above, this solution should work for people using the PHP SoapServer functionality directly, as well as Zend Framework users.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.
By submitting this form, you accept the Mollom privacy policy.