1

Hello I've to consume SOAP service in java I've generated proxy class here is the list of classes which are generated

1)Bill.java
2)BillInfo.java
3)GetBillInfo.java
4)GetBillInfoResponse.java
5)ObjectFactory.java

now Sample input given to me by client is as following

-<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-<soap:Body>
-<bil:getBillInfo xmlns:ns2="http://billpay.ws.bi.com/" xmlns:bil="http://billpay.ws.bi.com/">
-<billInfo>
-<bill>
<consumerNo>10300075929</consumerNo>
<shortName>SNGPL</shortName>
</bill>
<channel_id>100</channel_id>
<password>XXXXXX</password>
<username>xxx</username>
<webServiceID>3000</webServiceID>
<STAN>439624</STAN>
<channelType>Mobile</channelType>
</billInfo>
</bil:getBillInfo>
</soap:Body>
</soap:Envelope>

and output from this input is as follows

-<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
-<S:Body>
-<ns2:getBillInfoResponse xmlns:ns2="http://billpay.ws.bi.com/">
-<return>
-<bill>
<billAmount>150.00</billAmount>  
<billConsumerName>GOHER PIRZADA </billConsumerName>
<billMonth>2016-01</billMonth>
<consumerNo>10300075929 </consumerNo>
<dueDate>2017-08-19</dueDate>
<lateAmount>160.00</lateAmount>
<shortName>SNGPL</shortName>
<utilityCompanyAccount>900083181010586</utilityCompanyAccount>
</bill>
<channel_id>0</channel_id>
<password/>
<status>Processed OK</status>
<statusCode>0</statusCode>
<username/>
<webServiceID>0</webServiceID>
</return>
</ns2:getBillInfoResponse>
</S:Body>
</S:Envelope>

these are the sample which are given to me now to implement this service for which I've written the following code but it does not work and does not return values please look into my code

GetBillInfo gbi = new GetBillInfo();
    BillInfo bi = new BillInfo();
    bi.setChannelId(100);
    bi.setPassword("XXXXXX");
    bi.setUsername("xxx");
    bi.setWebServiceID(3000);
    bi.setChannelType("Mobile");
    bi.setSTAN("439624");
    Bill bill = new Bill();
    bill.setConsumerNo("10300012345");
    bill.setShortName("SNGPL");
    gbi.setBillInfo(bi);

    ObjectFactory of=new ObjectFactory();
    JAXBElement<GetBillInfo> jbx = of.createGetBillInfo(gbi);

Here I do not get any response please let me know what mistake I'm making. Please let me know how to call which code by looking at the SOAP input and output values

Jahangeer
  • 486
  • 1
  • 6
  • 20
  • The ObjectFactory only creates the objects you need to send. What is missing is the actual service class, which has a method, probably getBillInfo, to which you can give the object as a parameter. – Florian Schaetz Jun 01 '17 at 05:47
  • objectFactory class have these two methods @XmlElementDecl(namespace = "http://billpay.ws.bi.com/", name = "getBillInfo") public JAXBElement createGetBillInfo(GetBillInfo value) { return new JAXBElement(_GetBillInfo_QNAME, GetBillInfo.class, null, value); } – Jahangeer Jun 01 '17 at 05:57
  • The ObjectFactory is just for creating the classes, it will not send or receive anything. Ok, let's start the other wayy round... How did you create your proxy classes? wsimport? – Florian Schaetz Jun 01 '17 at 05:57
  • and @XmlElementDecl(namespace = "http://billpay.ws.bi.com/", name = "getBillInfoResponse") public JAXBElement createGetBillInfoResponse(GetBillInfoResponse value) { return new JAXBElement(_GetBillInfoResponse_QNAME, GetBillInfoResponse.class, null, value); } – Jahangeer Jun 01 '17 at 05:58
  • this is how I generated my proxy classes from the following example http://memorynotfound.com/spring-ws-consume-soap-service-wsdl/ – Jahangeer Jun 01 '17 at 05:59
  • Seems like a horrible complicated way to create a client, google `wsimport`, which is a java standard tool and will give you some classes you can use without further configuration needed. Otherwise follow the other instructions on that page to use your classes to send the data. – Florian Schaetz Jun 01 '17 at 06:01
  • could u please tell how generate proxy classes with wsimport for Spring Boot application in Eclipse – Jahangeer Jun 01 '17 at 06:23

3 Answers3

2

One basic way of accessing a SOAP WebService is via wsimport, which is a java standard tool, included in the jdk.

Basically, you are calling it like this...

wsimport -Xnocompile http://example.com/someService?wsdl

...or whatever the location of your wsdl is, can be a local file, too. You can customize it by giving the parameters -d (destination folder) and -p (the package you want to create). The -Xnocompile parameter simply makes it give you .java files and not compiled .class files.

After you used that command, you will get some clases. you can then use them like this...

BillService service = new BillService();
BilLServicePortType port = service.getBillServicePort();
ObjectFactory of=new ObjectFactory();
JAXBElement<GetBillInfo> jbx = of.createGetBillInfo(gbi);

There's no need to actually use Spring here, but of course you can define beans for the service, etc., no problem there.

Florian Schaetz
  • 10,454
  • 5
  • 32
  • 58
0

Open your command prompt and you have to enter wsimport command wsimport -p xxx.xxx.xxx -s D:\xxx\xxx http://xxxx:8080/xxxx/xxx?wsdl

here -s is a source folder which you have to create in your system.Once you execute this command you will get java file, copy that java file to your project. Then ` YourSoapBindingService obj = new YourSoapBindingService (); YourService service = obj.getSoapBindingPort(); service.callYourServiceMethod();

`

Anand Sinha
  • 322
  • 3
  • 7
0

in addition to other answers wsimport is present in JDK installed directory for example for me its C:\Program Files\Java\jdk1.8.0_121\bin there is a file wsimport right click in the directory and use wsimport -Xnocompile pathToYOURWSDL and it will generate you java code,

Adeel Ahmed
  • 413
  • 4
  • 16