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