我正在尝试在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;
...
}
我实现了Web服务和方法。
@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>
,但我不想看到参数标签,我想看到以下类似
<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/文字。
查看本指南https://www.ibm.com/developerworks/library/ws-whichwsdl/查看所有方法之间的差异