我正在尝试创建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();
我很好奇为什么在wsdl中将WebResult名称与“ return”,在soap Response中将其与“ GetServerTimeProperty”以及在生成的stub中将其作为“”不同。
如果我不使用@WebResult(name =“ GetServerTimeProperty”)注释Web方法,则存根生成的客户端响应为null。
如果我使用@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注释如何在soap响应和客户端响应中有所作为。
每个“ operationName” +“ Respone”元素的名称都应该唯一吗?我的wsdl有很多同名的元素
请对此提出建议,如果我们不加注释,为什么WebResult名称将soap响应返回为null
答案 0 :(得分:0)
我进一步排除了
1。当两个webmethods方法具有相同的@WebResult(name =“ A”)时,我提到的两个方法的soapResponse结果名称有所不同
<wsdl-file>web-inf/wsdl/WebService.wsdl</wsdl-file>
在webservices.xml中明确显示。
2。删除webservices.xml中的<wsdl-file>
条目时,SoapResponse返回名称相同。不确定wsdl-file标签如何发挥作用。