Java – Web service client getting NullPointerException from getMyWSPort

javajax-wsnetbeansweb services

I have created a simple web service called TimeServerBean. It's working properly, the GlassFish server is running and I can access the WSDL file from browser. Note this is done on local host.

Next I created a new project and made a web service client and provided the URL to the WSDL file. Then I got some classes generated (JAX-WS).
On my client class I have this code:

public class SimpleClient {

    @WebServiceRef(wsdlLocation = "wsdl url here")
    static TimeServerBean_Service service;
    private TimeServerBean bean;

    public SimpleClient() {
         bean = service.getTimeServerBeanPort();
    }
    //methods here
}

Although I get null when I call the getTimeServerBeanPort. During that time the server is up and running. Is there some obvious mistake? TimeServerBean and TimeServerBean_Service are generated classes from the WSDL.

Best Answer

Two suggestions:

  1. DEFINITELY put your method in a try/catch block

  2. Assuming that service itself is null, then try doing an explicit service.create() instead of using the @WebServiceRef annotation. Here's a good example (Websphere, but same principle):

http://www-01.ibm.com/support/docview.wss?uid=swg21264135