简体   繁体   中英

Create a SOAP Webservice Client Application in Java

I have created in eclipse a Webservice in Java using Apache CXF , now I have to create a WebService client application to consume and invoke it. I have been searching a way to do it, and I found that Client is always dependent to the server's Java Class.

The problem is that I have to develop a client class in an other Java environment. My question is : Is there a way to develop a client class which will be independent of webservice server's package, using only the WSDL file ?

Thank you :)

You can take help of Apache CXF Link wsdl to java tool. wsdl2java - takes a WSDL document and generates fully annotated Java code from which to implement a service.

You can take help of eclipse plugin also.

Eclipse plugin to generate java class

You can send request to web service API as XML request. Only thing you would need to constuct SOAP complaint request with proper header and body. By using SoapUI you can generate the XML request structure, and then reuse it in your application.

If you are using Jax-RS(REST APIs), even http method also works

[update]

If you are stuck with how to create client classes, then you would follow this

  1. Use wsimport

     > http : //hostname :port/wsdl.url on command line to create proxy classes
  2. Create jar file generated proxy classes

  3. Add jar file to class path
  4. Use Service API to construct the end point, and then invoke service.
  5. Sample test client is given below.

     try { URL wsdlURL = new URL("http://localhost:8082/cxf/services/yourservice?wsdl"); QName SERVICE_NAME = new QName("http://package.name/","PORTNAme"); Service service = Service.create(wsdlURL, SERVICE_NAME); client = service.getPort(PORTInterface.class); client.executeYourMethod() } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }

  1. URL is WSDL url
  2. To create QName, need to provide namespace of the service interface(revers name of package,usually) and PORT name which you can find in WSDL in binding section.
  3. Also need to identify the Proxy class ( name would be similar to port name)

Cheers Satheesh

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM