Zend_Soap_Server / PHP SoapServer 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 .”

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.