如何防止 JAX-WS Web 方法额外标记
How to Prevent JAX-WS Web Method Extra Tag
我正在尝试在 java 中使用 JAX-WS Web 方法。我遇到了一些设计问题。我试图更改从 Web 服务方法生成的 xml 结构。下面写了一些代码部分。我希望我能问我想要什么。
我创建了一个测试 java class 如下所示。
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"testKod"
})
@XmlRootElement(name = "testService")
public class TestService {
@XmlElement(required = true)
protected String testKod;
@XmlAttribute(required = true)
protected String uyeKod;
@XmlAttribute(required = true)
protected String islemRefNo;
...
}
我实现了网络服务和方法。
@WebMethod(operationName = "testService")
@WebResult(name="testServiceResponse")
public TestServiceResponse testService(@WebParam(name = "params") TestService params){
TestServiceResponse response = new TestServiceResponse();
try {
response.setUyeKod(params.getUyeKod());
response.setIslemRefNo(params.getIslemRefNo());
response.setTestKod(params.getTestKod());
} catch (Exception e) {
response.getHata().setAciklama(Convert.fromDBtoTR(TExceptionUtil.getExceptionMessage(e)));
response.getHata().setHataKodu("100");
}
return response;
}
我用 SAOP-UI 测试并导出 xsd 后,客户端请求如下所示。
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.ddd.ccc.bbb.aaa.com/">
<soapenv:Header/>
<soapenv:Body>
<ws:testService>
<params islemRefNo="1212" uyeKod="XXX" >
<testKod>1212</testKod>
</params>
</ws:testService>
</soapenv:Body>
</soapenv:Envelope>
但我不想看到 params 标签,我想看到如下所示
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.ddd.ccc.bbb.aaa.com/">
<soapenv:Header/>
<soapenv:Body>
<ws:testService islemRefNo="1212" uyeKod="XXX" >
<testKod>1212</testKod>
</ws:testService>
</soapenv:Body>
</soapenv:Envelope>
简要介绍一下我的 xsd 如下所示;
<xs:complexType name="testService">
<xs:sequence>
<xs:element name="params" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="testKod" type="xs:string"/>
</xs:sequence>
<xs:attribute name="uyeKod" type="xs:string" use="required"/>
<xs:attribute name="islemRefNo" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
但我想看起来像那样。我在回复中也遇到了同样的问题 xml.
<xs:element name="testService">
<xs:complexType>
<xs:sequence>
<xs:element name="testKod" type="xs:string"/>
</xs:sequence>
<xs:attribute name="uyeKod" type="xs:string" use="required"/>
<xs:attribute name="islemRefNo" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
这取决于您使用的是哪种样式绑定(RPC 或文档)。您可以使用以下注释指定它:
@SOAPBinding(
style=Style.RPC,
use=Use.LITERAL,
parameterStyle=ParameterStyle.BARE
)
我认为最适合您的配置是 RPC/Literal。
查看本指南https://www.ibm.com/developerworks/library/ws-whichwsdl/了解所有方法之间的区别
我正在尝试在 java 中使用 JAX-WS Web 方法。我遇到了一些设计问题。我试图更改从 Web 服务方法生成的 xml 结构。下面写了一些代码部分。我希望我能问我想要什么。
我创建了一个测试 java class 如下所示。
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"testKod"
})
@XmlRootElement(name = "testService")
public class TestService {
@XmlElement(required = true)
protected String testKod;
@XmlAttribute(required = true)
protected String uyeKod;
@XmlAttribute(required = true)
protected String islemRefNo;
...
}
我实现了网络服务和方法。
@WebMethod(operationName = "testService")
@WebResult(name="testServiceResponse")
public TestServiceResponse testService(@WebParam(name = "params") TestService params){
TestServiceResponse response = new TestServiceResponse();
try {
response.setUyeKod(params.getUyeKod());
response.setIslemRefNo(params.getIslemRefNo());
response.setTestKod(params.getTestKod());
} catch (Exception e) {
response.getHata().setAciklama(Convert.fromDBtoTR(TExceptionUtil.getExceptionMessage(e)));
response.getHata().setHataKodu("100");
}
return response;
}
我用 SAOP-UI 测试并导出 xsd 后,客户端请求如下所示。
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.ddd.ccc.bbb.aaa.com/">
<soapenv:Header/>
<soapenv:Body>
<ws:testService>
<params islemRefNo="1212" uyeKod="XXX" >
<testKod>1212</testKod>
</params>
</ws:testService>
</soapenv:Body>
</soapenv:Envelope>
但我不想看到 params 标签,我想看到如下所示
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.ddd.ccc.bbb.aaa.com/">
<soapenv:Header/>
<soapenv:Body>
<ws:testService islemRefNo="1212" uyeKod="XXX" >
<testKod>1212</testKod>
</ws:testService>
</soapenv:Body>
</soapenv:Envelope>
简要介绍一下我的 xsd 如下所示;
<xs:complexType name="testService">
<xs:sequence>
<xs:element name="params" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="testKod" type="xs:string"/>
</xs:sequence>
<xs:attribute name="uyeKod" type="xs:string" use="required"/>
<xs:attribute name="islemRefNo" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
但我想看起来像那样。我在回复中也遇到了同样的问题 xml.
<xs:element name="testService">
<xs:complexType>
<xs:sequence>
<xs:element name="testKod" type="xs:string"/>
</xs:sequence>
<xs:attribute name="uyeKod" type="xs:string" use="required"/>
<xs:attribute name="islemRefNo" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
这取决于您使用的是哪种样式绑定(RPC 或文档)。您可以使用以下注释指定它:
@SOAPBinding(
style=Style.RPC,
use=Use.LITERAL,
parameterStyle=ParameterStyle.BARE
)
我认为最适合您的配置是 RPC/Literal。
查看本指南https://www.ibm.com/developerworks/library/ws-whichwsdl/了解所有方法之间的区别