Wednesday, November 18, 2009

Use Basic Types for Web Services

Today I encountered the following error message:

org.apache.axis2.databinding.ADBException: Any type element type has not been given

I have defined my Web Service code as follows:

public ArrayList ListNamesService();

When you generate the WSDL using wsdl2java, it creates a data type called, "anyType", which is WSDL's way of saying you'll be passing through an Object (of some indeterminate type). This generates the above runtime error.

The solution is to do this:

public String[] ListNamesService();

which may seem archaic given the Java Collections classes, but at least an array of Strings is compatible across all platforms (which is a great benefit). So, aside from getting the error messages to go away, use basic types for Web Services.

1 comment:

  1. BTW, here's a great reference on the topic: http://www.ibm.com/developerworks/webservices/library/ws-tip-coding.html

    ReplyDelete