通过调用生成的代理类来使用SOAP WSDL

时间:2017-06-01 05:37:52

标签: java web-services soap wsdl

您好我在java中使用SOAP服务我在这里生成的代理类是生成的类列表

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

现在客户提供给我的样本输入如下

-<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>

此输入的输出如下

-<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>

这些是我现在提供给我的样本,我已经为此编写了以下代码,但它不起作用且不返回值请查看我的代码

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);

我在这里没有得到任何回复,请让我知道我犯了什么错误。请通过查看SOAP输入和输出值

告诉我如何调用哪些代码

3 个答案:

答案 0 :(得分:1)

访问SOAP WebService的一种基本方法是通过wsimport,这是一个java标准工具,包含在jdk中。

基本上,你这样称呼它......

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

...或者wsdl的位置,也可以是本地文件。您可以通过提供参数-d(目标文件夹)和- p(您要创建的包)来自定义它。 -Xnocompile参数只是让它为你提供.java文件而不是编译的.class文件。

使用该命令后,您将获得一些分支。你可以像这样使用它们......

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

这里没有必要真正使用Spring,但当然你可以为服务定义bean等等,没问题。

答案 1 :(得分:0)

打开命令提示符,您必须输入wsimport command wsimport -p xxx.xxx.xxx -s D:\xxx\xxx http://xxxx:8080/xxxx/xxx?wsdl

此处-s是您必须在系统中创建的源文件夹。一旦执行此命令,您将获得java文件,将该java文件复制到您的项目中。 然后 `YourSoapBindingService obj = new YourSoapBindingService();    YourService service = obj.getSoapBindingPort();    service.callYourServiceMethod();

`

答案 2 :(得分:0)

除了其他答案 wsimport存在于JDK安装目录中,例如对我而言 C:\ Program Files \ Java \ jdk1.8.0_121 \ bin 有一个文件wsimport 右键单击目录并使用wsimport -Xnocompile pathToYOURWSDL,它将生成java代码,

相关问题