Setting up complex data types in WSDL

Putting SOAP service on PHP platform is a piece of cake. There are few nice articles out there that will pretty much guide you through the whole setup(which is in fact just putting together WSDL and server-side functions to handle a request), so after half an hour of messing around you can have your own SOAP thingie going. One draw back there – the article would get you as far as sending simple types(like strings and floats) back and force between client and server. Now, this isn’t very helpful if you’re trying to build something more object oriented.

The basic problem that I hit setting up SOAP server for a data-sharing application(pretty much content repository for a network of websites) – how to set up a custom complex data type without going through that whole WSDL spec?

I needed SOAP server to response with an Array of Objects. Two things needed to be done to achieve that – add custom type definition for the object and for the array.

WSDL has a special section <types> where you can do that. Here is an example:

<types>
<xsd:schema targetNamespace="http://www.ecerami.com/schema" xmlns="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="FeedItem">
<xsd:sequence>
<xsd:element minOccurs="1" maxOccurs="1" name="InternalID" type="xsd:int" />
<xsd:element minOccurs="1" maxOccurs="1" name="PostedDate" type="xsd:string" />
<xsd:element minOccurs="1" maxOccurs="1" name="Head" type="xsd:string" />
<xsd:element minOccurs="1" maxOccurs="1" name="SourceName" type="xsd:string" />
<xsd:element minOccurs="1" maxOccurs="1" name="Subhead" type="xsd:string" />
<xsd:element minOccurs="1" maxOccurs="1" name="Author1" type="xsd:string" />
<xsd:element minOccurs="1" maxOccurs="1" name="Author2" type="xsd:string" />
<xsd:element minOccurs="1" maxOccurs="1" name="Author3" type="xsd:string" />
<xsd:element minOccurs="1" maxOccurs="1" name="Source" type="xsd:string" />
<xsd:element minOccurs="1" maxOccurs="1" name="Groupword" type="xsd:string" />
<xsd:element minOccurs="1" maxOccurs="1" name="Body" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</types>

This is an object. To have an array of objects I needed to put extra stuff into the <types> section:

<complexType name="FeedItemList">
<complexContent>
<restriction base="soapenc:Array">
<attribute ref="soapenc:arrayType"  wsdl:arrayType="xsd1:FeedItem[]"/>
</restriction>
</complexContent>
</complexType>

The last thing was to modify return type of the Response message

<message name='getLatestFeedResponse'>
<part name='list' type='xsd1:FeedItemList' />
</message>

And that’s pretty much it as far as WSDL concerned. Piece a cake ;)

There is a great book, that actually describes WSDL(and all the other web-service related technologies) in a greater details. Part that I needed was free :)

3 thoughts on “Setting up complex data types in WSDL

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>