顾乔芝士网

持续更新的前后端开发技术栈

webservice更改返回信息节点名称

问题详情:

<!--访问webservice中,返回的信息-->
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <ns2:testResponse xmlns:ns2="http://test.webservice">
            <return>
                <msg>成功</msg>
                <status_code>1</status_code>
            </return>
        </ns2:testResponse>
    </soap:Body>
</soap:Envelope>
<!--WSDLZ中定义的返回参数节点-->
<xs:complexType name="testResponse">
                <xs:sequence>
                    <xs:element minOccurs="0" name="return" type="tns:baseInfo"/>
                </xs:sequence>
  </xs:complexType>

解决办法:

如上图,默认webservice的接口返回信息中,return是默认的返回节点,无法直接更改元素的name属性,如果要更改其名称,可以在访问的接口方法上添加@WebResult属性,这样默认的return就会更改为data

@WebMethod
@WebResult(name = "data", targetNamespace = "")
public BaseInfo callBussiness(@WebParam(name = "message") String message);

结果展示:

总结:

jkd自动带了生成webservice的代码,个人看了,多了好几个类,非常不喜欢,这种方式写的代码,很简洁,少了很多的冗余代码和类,个人还是比较喜欢这种方式的。

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言