How to prevent namespace wrapper tags in SOAP wsdl?

给你一囗甜甜゛ 提交于 2019-12-25 07:19:16

问题


I created a wsdl webservice with cxf.

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

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.

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

Resulting wsdl structure:

Request:

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

Response:

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

回答1:


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

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>

And response would be

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


来源:https://stackoverflow.com/questions/38503346/how-to-prevent-namespace-wrapper-tags-in-soap-wsdl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!