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.
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
Use wsimport
> http : //hostname :port/wsdl.url on command line to create proxy classes
Create jar file generated proxy classes
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(); }
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.