jax-ws中SOAPBinding的使用姿势

客户端的请求报文格式如下,并且格式不能改动

<?xml version="1.0"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <ns1:MessageHeader xmlns:ns1="http://XX.com/AA/checkData" soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0">
            <ns1:AppID>AA</ns1:AppID>
            <ns1:Provide_AppID>BB</ns1:Provide_AppID>
        </ns1:MessageHeader>
    </soapenv:Header>
    <soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <ns2:checkData xmlns:ns2="http://XX.XX.com:8080/PendDataImport_app/services/PendDataImport" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
            <ns2:lastTime xsi:type="xsd:string">2018-01-20 00:23:14</ns2:lastTime>
            <ns2:item xsi:type="xsd:string">aaaa</ns2:item>
        </ns2:checkData>
    </soapenv:Body>
</soapenv:Envelope>

客户端在每个请求方法里面添加了自定义的命名空间,要求服务端跟它保持一致。

我当时想,这还不简单,发布服务的时候,指定命名空间不就好了。代码如下:

@WebService(targetNamespace = "http://XX.XX.com:8080/PendDataImport_app/services/PendDataImport")
public interface HelloService {
    @WebMethod
    String checkData( @WebParam(name="lastTime")String lastTime, @WebParam(name="item")String item);
}


但是测试时,请求报文却怎么也通不过。报错信息:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Client</faultcode>
         <faultstring>Unmarshalling Error: 意外的元素 (uri:"http://XX.XX.com:8080/PendDataImport_app/services/PendDataImport", local:"lastTime")。所需元素为<{}lastTime>,<{}item></faultstring>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

在看https://www.cnblogs.com/fsjohnhuang/articles/2340335.html这篇文章后,有所启发。


将服务端代码修改了一点,如下:

@WebService(targetNamespace = "http://XX.XX.com:8080/PendDataImport_app/services/PendDataImport")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public interface HelloService {
    @WebMethod
    String checkData( @WebParam(name="lastTime")String lastTime, @WebParam(name="item")String item);
}

再次测试验证,结果通过。



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值