Problems with Webservices in Netbeans and how to solve them

Ok, rather than give a tutorial on web services – because there are some around, I thought I would solve one of the mysterious problems that can occur when you are creating these services.

Netbeans is AMAZING at creating web services, the tools are incredibly rich.

But this error dogged me. I had one or two web services that worked and others that didn’t. To set up my service I had set up some inner classes

public static class dtaData {
private String Name;
private String date;
private String sid;

then created a web services that returned a LIST of those objects:-

    @WebMethod(operationName = "Data")
    public List Data() {
        List result=new ArrayList();
       for (int i=0;i<20;++i) {
        dtaData DataObject=new dtaData ();

        return result;

And it falls over with this error when you test the webserver. HOWEVER The problem is caused because there is no web service DIRECTLY returning the dtaData class. The solution is to create a web service that returns null but has dtaData as the returning Object.


    @WebMethod(operationName = "testData")
    public dtaData testData() {
           return null;


These errors are given when the problem occurs:-

On the glassfish server

Caused by: javax.xml.bind.MarshalException
 - with linked exception:
[javax.xml.bind.JAXBException: class PHJ.Agenda$ICDB_Agenda_data nor any of its super class is known to this context.]

On the web service test return:

Exceptions details : java.lang.reflect.InvocationTargetException

javax.servlet.ServletException: java.lang.reflect.InvocationTargetException at com.sun.enterprise.webservice.monitoring.WebServiceTesterServlet.doPost( at com.sun.enterprise.webservice.monitoring.WebServiceTesterServlet.invoke( at com.sun.enterprise.webservice.JAXWSServlet.doPost( at javax.servlet.http.HttpServlet.service( at javax.servlet.http.HttpServlet.service( at org.apache.catalina.core.ApplicationFilterChain.servletService( at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter( at org.apache.catalina.core.Ap


About Paul C

I am a Senior Java programmer/Web Technologies, Play in a band called Mandolin Monday, I have a cat and I live on a boat.

Posted on October 1, 2008, in Netbeans and tagged , , , , , . Bookmark the permalink. 2 Comments.

  1. A better solution using generics:
    @WebMethod(operationName = “Data”)
    public List Data() {
    List result=new ArrayList();
    for (int i=0;i<20;++i) {
    dtaData DataObject=new dtaData ();
    Thus wsimport can generate the dtaData class.. Your workaround is a good solution when inheritance is required and parent or child classes are not explicitly returned in a webservice.

  2. Yes agreed thanks for that one Daniel.

    Incidentally this was a very interesting project, I had to get the data to Italy with specifications they wrote for their database. They had one database, I had 36.

    So everytime they requested a web service my system had to scan 36 different schemata in a SQL SERVER 2005. I used my JTDS driver and a special class to make it look to the other end that it was one database. Lucikly the Primary keys in the databases were all UUID’s so we didn’t have a problem with multple clients for instance with the same IDs.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: