我使用wsdl
创建了cxf
网络服务。
问题:我的请求和响应都包含一个带命名空间的额外包装元素。
问题:是否可以阻止此包装元素?因为对我而言,它没有增加任何价值,而当其他人使用我的网络服务时,它只是一个额外的元素。
例如,我希望将以下示例中的<com:MyNameOperation><MyNameReq>
hierar减少为一个元素,而不是两个嵌套元素。
@WebService(name = "myname", serviceName = "myname", targetNamespace = "com.test")
publi class MySoapServlet {
@WebMethod(operationName = "MyNameOperation")
@WebResult(name = "MyNameResult")
public MyResponse getRsp(@WebParam(name = "MyNameReq") MyNameReq req) {
//return...
}
}
@XmlRootElement(name = "MyNameResponse")
@XmlAccessorType(XmlAccessType.FIELD)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class MyNameResponse {
private String name;
}
产生的wsdl结构:
请求:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:de="com.test">
<soapenv:Header/>
<soapenv:Body>
<!-- how can I omit this namespace element completely? -->
<com:MyNameOperation>
<MyNameReq>
...
</MyNameReq>
</com:MyNameOperation>
</soapenv:Body>
</soapenv:Envelope>
响应:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<!-- how can I omit this namespace element completely? -->
<ns2:MyNameResponse xmlns:ns2="com.test">
<MyNameResult>
<name>somevalue</name>
</MyNameResult>
</ns2:MyNameResponse>
</soapenv:Body>
</soapenv:Envelope>
答案 0 :(得分:2)
您可以使用参数样式BARE @SOAPBinding(parameterStyle=ParameterStyle.BARE)
。但是,您无法完全删除2个级别,因为需要操作名称来标识操作。更新后的课程如下所示
@WebService(name = "myname", serviceName = "myname", targetNamespace = "com.test")
@SOAPBinding(parameterStyle=ParameterStyle.BARE)
publi class MySoapServlet {
@WebMethod(operationName = "MyNameOperation")
@WebResult(name = "MyNameResult")
public MyResponse getRsp(@WebParam(name = "MyNameReq") MyNameReq req) {
//return...
}
}
更新的请求xml将是。
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:de="com.test">
<soapenv:Header/>
<soapenv:Body>
<com:MyNameReq>
<name >data</name>
</com:MyNameReq>
</soapenv:Body>
</soapenv:Envelope>
响应将是
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<!-- how can I omit this namespace element completely? -->
<ns2:MyNameResult xmlns:ns2="com.test">
<name>somevalue</name>
</ns2:MyNameResult>
</soapenv:Body>
</soapenv:Envelope>