Hi,
I get a NullPointerException when attempting to use dependency injection in a web service Client program. I have been trying to figure out this problem for a while now. The article
Unmanaged JAX-WS clients do not allow injection of @WebServiceRef or @WebServiceRefs resources on IBM's support website provides a clue.
After searching all over the place for a solution, I could not find it ... until I started reading the
Java EE 5 tutorial.

Its on Page 488 of the Java EE 5 tutorial PDF. After some guessing, the following works.
This is using NetBeans
IDE 6.8 (needless to say, I don't know how to do the same thing in Eclipse)
Project structure looks like this:
HelloWs (Create a project of type
Java Web->Web Application)-->Web Services-->HelloWebService
Create the web service project
Create a web service called HelloWebService in the project, and
make a note of the service name you provide.
@WebService(
serviceName="
GreeterWs")
@WebMethod(operationName = "sayHello")
public
String sayHello(@WebParam(name = "name") String name) {return "Hello" + name;}
Create a client project
HelloWsClient (Project type is
Java EE->Enterprise Application Client)
// note that HelloWs is the project and GreeterWs is the exposed service name
@WebServiceRef(wsdlLocation="
http://localhost:8080/HelloWs/GreeterWs?wsdl")
GreeterWs service; // will be injected. note the data type of the variable. its the service name provided in the @WebService annotation
HelloWebService ws = service.getHelloWebServicePort();
System.out.println ("HelloWebService returned: " + ws.sayHello("Saying hello!"));
Make sure that you can see the wsdl. Right-click the client project and select Run File, and it should work.
Hope this is helpful to someone!
Now a question if you are still reading this.

I am assuming that we just created a "managed" JAX-WS client. This works because I have Glassfishv3 on my local machine. What if the web service were on a remote server and the local machine running the client did not have Glassfish installed? So there is nothing on the client side to "manage" it. Would the client still work?
Regards,
Srini