gpt4 book ai didi

java - 如何防止 SOAP wsdl 中的 namespace 包装器标记?

转载 作者:行者123 更新时间:2023-12-02 03:28:11 24 4
gpt4 key购买 nike

我创建了一个wsdl网络服务 cxf .

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

问题:是否可以阻止此包装元素?因为对我来说它没有增加任何值(value),而只是其他人使用我的网络服务时的附加元素。

例如,我想减少 <com:MyNameOperation><MyNameReq>以下示例中的 hierarchie 只是一个元素,而不是两个嵌套元素。

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

最佳答案

您可以使用parameterstyle 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>

关于java - 如何防止 SOAP wsdl 中的 namespace 包装器标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38503346/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com