How to create a Java client for a web service?

I have successfully created a web service . I tested it and got a WSDL file. the client that will use this web service is a simple Java class.

I can create a jsp client and call web service methods. But I need to call a web service from a Java class.

How do I bind to this Java client with a web service?

I completed the following steps in NetBeans to create a Java client ...

  • I created a simple J2SE application.
  • Made it a WebService web service client made by me.
  • I get links to the web service of my WebService.

But I can not name the WebService method. 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; } } 
+6
source share
2 answers

You can use the wsimport tool to create client stub files from the command line:

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

then import the created files and use them as you did above

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

There are also some frameworks for working with web services, such as Apache CXF and the Apache Axis

Update: just noticed that the old question, if the OP knew the answer, it should update the topic.

+2
source

You can try Jersey and Client API

0
source

Source: https://habr.com/ru/post/909334/


All Articles