如何防止SOAP wsdl中的名称空间包装器标签? [英] How to prevent namespace wrapper tags in SOAP wsdl?

查看:77
本文介绍了如何防止SOAP wsdl中的名称空间包装器标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 cxf 创建了 wsdl 网络服务。

问题:我的请求和响应都包含一个带有名称空间的额外包装器元素。

Problem: both my request and response contain an extra wrapper element with the namespace.

问题:是否可以防止该包装器元素?因为对我来说,它没有任何价值,只是其他人使用我的Web服务时的附加元素。

Question: is it possible to prevent this wrapper element? Because for me it adds no value, and is just an additional element when others would use my webservice.

例如,我想减少< com:MyNameOperation>< MyNameReq> 层次结构只是一个元素,而不是两个嵌套元素。

For example I'd like to reduce the <com:MyNameOperation><MyNameReq> hierarchie in the following example to be just one element, not two nested elements.

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


推荐答案

您可以使用参数样式BARE @SOAPBinding(parameterStyle = ParameterStyle.BARE)。但是,由于需要使用操作名称来标识该操作,因此您无法完全删除这两个级别。更新的类如下所示

You can user parameterstyle BARE @SOAPBinding(parameterStyle=ParameterStyle.BARE). However you cannot completely remove the 2 levels, since operation name is required to identify the operation. Updated class would look like as shown below

@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是。

The updated request xml would be.

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

这篇关于如何防止SOAP wsdl中的名称空间包装器标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆