rel1kz
rel1kz

Reputation: 73

Java classes to generate SOAP requests from wsdl

I am looking for a way to easily generate SOAP requests from a wsdl file. for example, something like this:

WSDLObject myWsdl = new WSDLObject("http://www.whatever.com/myService?wsdl");
SOAPRequest myRequest = myWsdl.generateSOAPRequest();

Is there anything like that?

I am trying to do it dynamically via another application, so tools like WSDL2Java dont work for me (at least I think). I need to be able to generate these requests from user input, and then work with them from there.

any help is appreciated.

Upvotes: 1

Views: 6360

Answers (2)

Cuga
Cuga

Reputation: 17904

Please see this answer: How to get response from SOAP endpoint?

What you basically want to do is use the wsimport tool that ships with the JDK. So long as Java is on your system's classpath, you should be able to go to any terminal or console and do:

wsimport http://www.whatever.com/myService?wsdl -p com.company.whateveruwant -d . -keep

With a choice of options (-d specifies the directory to output the generated code). This being done, you'll be able to invoke the web service with the auto-generated code quite simply, such as like:

CustomInterface soap = new CustomEndpoint().getCustomInterface();
System.out.println(soap.getAnswerFromWs("ParamValue"));

Upvotes: 1

zoomer.hammerball
zoomer.hammerball

Reputation: 83

You can with WSDL2Java, the unique change is that you work with Java proxy objects and set the attributes of this objects to generate the SOAP request. Other way is use SOAPUI, for example to generate the SOAP message, and directly construct your SOAP message as StringBuffer and use directly a socket to call the service composing the complete HTTP/SOAP message from scratch.

Upvotes: 0

Related Questions