6

I have successfully created Web Service. Tested it and getting the WSDL file also. The client that will use this Web Service is a simple Java class.

I am able to create a jsp client and call the methods of Web Service. But I need to call the Web Service from a Java class.

How do I bind this Java client with Web Service?

The following steps I followed in NetBeans for creating the Java Client...

  1. I created a simple J2SE Application.
  2. Made it a Web Service Client of the WebService made by me.
  3. I'm getting the Web Service References of my WebService.

But I'm not able to call the method of the WebService. Here is the Client file...

package client_package;
public class client {

public static void main(String args[])
{
   System.out.println("1");
   System.out.println(hello("megha"));
   System.out.println("2");
}
private static String hello(String name) {


    WS_package.WebService1 service = new WS_package.WebService1(); //package WS_package does not exists
    WS_package.WebService1 port = service.getWebService1Port(); //package WS_package does not exists


 name =  port.hello(name);

return name;
}
}
Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
jQueen
  • 552
  • 1
  • 7
  • 16
  • This may help (in general): http://stackoverflow.com/questions/209385/java-webservice-client – Andreas Dolk Feb 25 '12 at 07:15
  • 1
    Do you get an exception when you run this code? If so, can we see the stack trace? – Michael Righi Feb 25 '12 at 07:17
  • @MichaelRighi, yes I'm getting an error that package WS_package does not exist. and so i'm not able to use methods of it. port is not getting created and hence method `port.hello(name)` is not being called – jQueen Feb 25 '12 at 07:36

2 Answers2

2

You could use wsimport tool to generate a client stub files, from command line:

wsimport -keep http://localhost:8080/webservices/helloService?wsdl

then import the generated files and use them like you did above

HelloServiceImplService helloService = new HelloServiceImplService();
HelloService hello = helloService.getHelloServiceImplPort();

There are also some frameworks arround to work with Webservices, like Apache CXF and Apache Axis

Update: Just noticed its an old question, if the OP knew the answer, he should update the topic.

Community
  • 1
  • 1
Ahmed M Farghali
  • 319
  • 3
  • 12
0

You could try Jersey and its Client API

Alex Stybaev
  • 4,623
  • 3
  • 30
  • 44
  • I'm now able to bind the simple java client to my webservice. Both reside on single machine. what should I do to bind – jQueen Mar 02 '12 at 11:36