Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 23,874 times

Contents

Related Categories

Web Services Interoperability between J2EE and .NET - Part 2 - Collection of complex data types (contd)

Wangming Ye

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[]

    [WebMethod]
    [XmlInclude(typeof(Product))]
    public Product[] updateProductPriceFacade(Product[] products)
    {
        ArrayList alist = new ArrayList();
        IEnumerator it = products.GetEnumerator();
        while (it.MoveNext())
            alist.Add((Product)(it.Current));
        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 .

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 (later merged into IBM), and then as one of the main developers of the WebSphere Content Distribution Framework in the WebSphere Edge Server group. He currently provides technical enablement for WebSphere business partners in the WebSphere Competency Center in the IBM Business Partner Technical Enablement organization.

Comments

  • Null parameters

    Posted by nrsimoes on 16 Jan 2006

    I'm developing a .NET Web Service that have some functions with datetime parameters but the I can't call it from Java client with nulls. Can you explain me how to define a complex type to wrap the val...

  • But how... ?

    Posted by stefantura on 14 Jul 2005

    Hi,

    Nice article - but what sould go next - some examples (or maybe names of solutions) of software which translates between different SOAP datatypes... There have to be such a frameworks for type ...