【发布时间】:2017-03-10 14:17:19
【问题描述】:
我正在尝试在 java 中使用 JAX-WS Web 方法。我遇到了一些设计问题。我试图更改从 Web 服务方法生成的 xml 结构。一些代码部分写在下面。我希望我能问我想要什么。
我创建了一个如下所示的测试 java 类。
@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>
【问题讨论】:
标签: java xml web-services xsd jax-ws