Zend_Soap_Autodiscover and Importing the SOAP Namespace

Zend_Soap_Autodiscover has improved dramatically between 1.6.0 and 1.7.2. For starters, the generated WSDL actually validates correctly! Well, almost correctly...

After changing the interface of a recently developed Web Service to include an array of objects, I started receiving some really annoying validation errors, such as:

The inline schema uses an element from the SOAP encoding namespace but the namespace has not been imported. The SOAP encoding namespace should be imported with an import statement before it is used.

Depending on which validator I used, I also had this error come up:

src-resolve.4.2: Error resolving component ’soap-enc:Array’. It was detected that ’soap-enc:Array’ is in namespace ’http://schemas.xmlsoap.org/soap/encoding/’, but components from this namespace are not referenceable from schema document ’file:///home/james/projects/ws/application/apiv1/apiv1.wsdl’. If this is the incorrect namespace, perhaps the prefix of ’soap-enc:Array’ needs to be changed. If this is the correct namespace, then an appropriate ’import’ tag should be added to ’file:///home/james/projects/ws/application/apiv1/apiv1.wsdl’.

“No problem”, I thought, “a quick Google search should solve this”. But alas, all of the solutions I found recommended adding the schemaLocation attribute to the import declaration, as follows:

<import namespace="http://schemas.xmlsoap.org/soap/encoding/"
schemaLocation="http://schemas.xmlsoap.org/soap/encoding/" />

However, that solution doesn’t actually work with the WSDL generated by Zend_Soap_Autodiscover. A solution that does work is to look through the WSDL generated by Zend_Soap_Autodiscover and find the types section. The first child node in that section will be the xsd:schema... declaration for the inline schema that defines the new data types being utilised by your web service. This will be followed by an <xsd:complexType...> declaration for the first of your custom data types. Insert a new declaration between the schema declaration and the complexType declaration that looks like this:

<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" />

This tells the inline schema that the soap-enc:Array data type that you’re referring to in your custom data types is from the SOAP namespace.

I don’t know enough about XML schema documents to know whether or not this is simply an oversight in Zend_Soap_Autodiscover or if there is some contention about whether or not it should be necessary. If you know the answer, please feel free to drop it in a comment below.

Yet Another Programming Blog

Where James Gordon rambles about PHP, Laravel and web development in general.

Find me on Google Plus Find me on Twitter Find me on Stack Exchange Find me on Github Subscribe