我正在尝试创建 Jax-ws WebServices。但坚持使用 JAX-WS 2.2 的这种行为。
我用以下方式编写了SEI类
@WebService
@SOAPBinding(parameterStyle=ParameterStyle.WRAPPED,use=Use.LITERAL,style=Style.DOCUMENT)
public class WebServicesServlet{
@WebMethod
public GetServerTimeProperty getServerTimeProperties(){
return new GetServerTimeProperty();
}
}
上述SEI生成的wsdl如下:
<types>
<xsd:schema>
<xsd:import namespace="http://soapCl.test/" schemaLocation="WebServicesService_schema1.xsd"/>
</xsd:schema>
</types>
<message name="getServerTimeProperties">
<part name="parameters" element="tns:getServerTimeProperties"> </part>
</message>
<message name="getServerTimePropertiesResponse">
<part name="parameters" element="tns:getServerTimePropertiesResponse"> </part>
</message>
和 XSD
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://soapCl.test/" version="1.0" targetNamespace="http://soapCl.test/">
<xs:element name="getTimeProperties" type="tns:getServerTimeProperties"/>
<xs:element name="getTimePropertiesResponse" type="tns:getServerTimePropertiesResponse"/>
<xs:complexType name="getServerTimeProperties">
<xs:sequence/>
</xs:complexType>
**<xs:complexType name="getServerTimePropertiesResponse">**
<xs:sequence>
**<xs:element name="return" type="tns:getServerTimeProperty" minOccurs="0"/>**
</xs:sequence>
</xs:complexType>
<xs:complexType name="getServerTimeProperty">
<xs:sequence>
<xs:element name="dayLightSavingHours" type="xs:int"/>
<xs:element name="observesDayLightSavings" type="xs:boolean"/>
<xs:element name="timeZoneDisplayName" type="xs:string"/>
<xs:element name="timeZoneId" type="xs:string"/>
<xs:element name="timeZoneValue" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
SOAP 响应:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<dlwmin:getServerTimePropertiesResponse xmlns:dlwmin="http://soapCl.test/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<GetServerTimeProperty>
<dayLightSavingHours>0</dayLightSavingHours>
<observesDayLightSavings>false</observesDayLightSavings>
</GetServerTimeProperty>
</dlwmin:getServerTimePropertiesResponse>
</soapenv:Body>
</soapenv:Envelope>
我尝试使用 wsimport 生成存根,这是我在生成的端口类中可以观察到的
@WebMethod
**@WebResult(targetNamespace = "")**
@RequestWrapper(localName = "getServerTimeProperties", targetNamespace = "http://soapCl.test/", className = "soapCl.test.GetServerTimeProperties")
@ResponseWrapper(localName = "getServerTimePropertiesResponse", targetNamespace = "http://soapCl.test/", className = "soapCl.test.GetServerTimePropertiesResponse")
@Action(input = "http://soapCl.test/WsSessionEJBEndPoint/getServerTimePropertiesRequest", output = "http://soapCl.test/WsSessionEJBEndPoint/getServerTimePropertiesResponse")
public GetServerTimeProperty getServerTimeProperties();
我很想知道为什么 WebResult 名称在 wsdl 中与“return”不同,在soap Response 中为“GetServerTimeProperty”,在生成的存根中为“”。
此外,如果我不使用 @WebResult(name="GetServerTimeProperty") 注释 Web 方法,我的存根生成的客户端响应为空。
如果我用@WebResult(name="GetServerTimeProperty") 注释我的网络方法,我的soapResponse 如下所示:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns2:getServerTimePropertiesResponse xmlns:ns2="http://soapCl.test/">
<return>
<dayLightSavingHours>0</dayLightSavingHours>
<observesDayLightSavings>false</observesDayLightSavings>
</return>
</ns2:getServerTimePropertiesResponse>
</soapenv:Body>
</soapenv:Envelope>
@WebResult(name) 在 jax-ws 中是强制性的吗?我很想知道这个 webresult 注释如何在肥皂响应和客户端响应中产生影响。
每个“operationName”+“Respone”元素的名称是否应该是唯一的?我的 wsdl 有许多同名的元素
请就此提出建议,如果我们不注释,为什么 WebResult 名称返回肥皂响应为 null