Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do a call through a javax.xml.ws.Service

Created a new standard java 7 project in Eclipse and have successfully managed to get an instance of a javax.xml.ws.Service like so:

  String wsdlURL = "http://example.com:3000/v1_0/foo/bar/SomeService?wsdl";
  String namespace = "http://foo.bar.com/webservice";
  String serviceName = "SomeService";
  QName serviceQN = new QName(namespace, serviceName);

  Service service = Service.create(new URL(wsdlURL), serviceQN);

This runs fine in a main method, so as far as I can see, that part works. But I can't figure out how to actually use it. In SoapUI I call this same service with a request which looks like the following:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://foo.bar.com/webservice">
   <soapenv:Header/>
   <soapenv:Body>
      <web:SomeWebServiceRequest acAccountName="name" acAccountPassword="password">
         <SomeRequest>
            <id>012345678901234</id>
            <action>Fix</action>
         </SomeRequest>
      </web:SomeWebServiceRequest>
   </soapenv:Body>
</soapenv:Envelope>

How can I do the same request in Java? My goal is that I have a long list of these ids, and I need to run a request like that for each of them. Doing it manually in SoapUI is a bit annoying, so I'd like to automate it with a simple Java console application.

like image 613
Svish Avatar asked Dec 12 '22 03:12

Svish


1 Answers

Next step is to get Port from your service:

Service service = Service.create(new URL(wsdlURL), serviceQN); // this is where you are.
QName portQName = new QName(portNamespace, portName);
YourPortInterface port = service.getPort(portQName, YourPortInterface.class);

YourPortInteface will be generated during wsimport or you can create and annotate it by yourself if you have enough experience in "reading" wsdl.

like image 97
andbi Avatar answered Dec 28 '22 13:12

andbi