Library tutorials & articles

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

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

Comments

  1. 16 Jan 2006 at 09:50

    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 value type and set the complex type to be null to indicate a null reference?


    Thanks

  2. 14 Jul 2005 at 13:21
    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 matching, aren't these?

    --
    best regards
    stic
  3. 01 Jan 1999 at 00:00

Leave a comment

Sign in or Join us (it's free).

Wangming Ye 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 m...
AddThis

Related podcasts

  • Open Source SOA

    The focus of this session will be to demonstrate innovative open source technologies and give you an insight into the skills, tools and techniques for SOA-enabling your enterprise architecture. This session will be taught via lecture as well as interesting live demonstrations (e.g. .NET linking t...

Events coming up

  • Nov 18

    15 Minutes of Fame

    Dresher, United States

    This is a yearly tradition. We select 10 of the favorite speakers from monthly meetings, code camps, and hands on labs. Each one does a 15 minute talk on their favorite .NET technology. This is our 10th anniversary so we plan a gala event with special prizes and refreshments.

We'd love to hear what you think! Submit ideas or give us feedback