Web Services Interoperability between J2EE and .NET - Part 2

Collection of complex data types (contd)

In fact, JAX-RPC generates the following helper class from the xsd:ArrayOfAnyType schema in Listing 2 .

Listing 3. The resulting helper class for the xsd:ArrayOfAnyType schema

public class ArrayOfAnyType  implements java.io.Serializable {
    private java.lang.Object[] anyType;
<!-- The setter, getter, equals() and hashCode() methods -->

From Listing 3 , you can see that the ambiguities in the xsd:ArrayOfAnyType schema have caused the JAX-RPC tool to generate the helper class with an generic java.lang.Object[] array as its private field instead of the concrete Product array.

To resolve this ambiguity, you can use ArrayOfRealType instead of the xsd:ArrayOfAnyType . You should only expose the simple array of concrete types (that is, Product[] ) as the signature of Web service methods.

For the Web service in Listing 1 , a facade method can be exposed:

Listing 4. Facade to expose the simple array Product[]

    public Product[] updateProductPriceFacade(Product[] products)
        ArrayList alist = new ArrayList();
        IEnumerator it = products.GetEnumerator();
        while (it.MoveNext())
        alist = updateProductPrice(alist);
        Product[] outArray = (Product[])alist.ToArray(typeof(Product));
        return outArray;

The new schemas for the input and output message parts are:

Listing 5. The XML Schema for the new Web service in Listing 4

1.    <s:element name="updateProductPriceFacade">
2.    <s:complexType>
3.    <s:sequence>
4.    <s:element minOccurs="0" maxOccurs="1" name="products"
type="s0:ArrayOfProduct" />
5.    </s:sequence>
6.    </s:complexType>
7.    </s:element>
8.    <s:complexType name="ArrayOfProduct">
9.    <s:sequence>
10.    <s:element minOccurs="0" maxOccurs="unbounded" name="Product"
type="s0:Product" />
11.    </s:sequence>
12.    </s:complexType>
13.    <s:element name="updateProductPriceFacadeResponse">
14.    <s:complexType>
15.    <s:sequence>
16.    <s:element minOccurs="0" maxOccurs="1"
name="updateProductPriceFacadeResult" type="s0:ArrayOfProduct" />
17.    </s:sequence>
18.    </s:complexType>
19.    </s:element>

From Line 8 to Line 12, the xsd:ArrayOfProduct schema is created to represent the concrete Product array. No ambiguity is present in the schema. As a result, the Web service client will have no problem in de-serializing the array of Products .

You might also like...


About the author

Wangming Ye United States

Wangming Ye is an IBM Certified Enterprise Developer and a Sun Certified Enterprise Architect for J2EE Technology. He began as a developer in the DCE/DFS department at Transarc Corporation (late...

Interested in writing for us? Find out more.


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The question of whether computers can think is just like the question of whether submarines can swim.” - Edsger W. Dijkstra