【发布时间】:2014-08-11 08:38:18
【问题描述】:
我正在尝试使用 eclipse、tomcat 和 cxf 部署一个简单的 Web 服务。
我正在遵循的步骤是:
1) 在动态 Web 项目的 WebContent 文件夹中创建一个 wsdl 文件。
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.negozio.org" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.negozio.org">
<wsdl:types>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.negozio.org" >
<xsd:complexType name="findTicketsRequest">
<xsd:sequence>
<xsd:element name="from" type="xsd:string" />
<xsd:element name="to" type="xsd:string" />
<xsd:element name="hour" type="tns:hourType" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="findTicketsResponse">
<xsd:sequence maxOccurs="unbounded">
<xsd:element name="ID" type="tns:IDType" />
<xsd:element name="hour" type="tns:hourType" />
<xsd:element name="minutes" type="tns:minutesType" />
<xsd:element name="quantity" type="xsd:integer" />
</xsd:sequence>
</xsd:complexType>
<xsd:simpleType name="hourType">
<xsd:restriction base="xsd:integer">
<xsd:minInclusive value="0"/>
<xsd:maxInclusive value="23"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="minutesType">
<xsd:restriction base="xsd:integer">
<xsd:minInclusive value="0"/>
<xsd:maxInclusive value="59"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="IDType">
<xsd:restriction base="xsd:string">
<xsd:pattern value="[0-9]{4}"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="ricercaRequest" type="tns:findTicketsRequest"></xsd:element>
<xsd:element name="ricercaResponse" type="xsd:boolean" />
</xsd:schema>
</wsdl:types>
<wsdl:message name="ricercaMessage">
<wsdl:part name="ricercaMessagePart" element="tns:ricercaRequest"/>
</wsdl:message>
<wsdl:message name="ricercaResponseMessage">
<wsdl:part name="ricercaResponsePart" element="tns:ricercaResponse"/>
</wsdl:message>
<wsdl:portType name="ServiceSearchPortType">
<wsdl:operation name="findTickets">
<wsdl:input message="tns:ricercaMessage" />
<wsdl:output message="tns:ricercaResponseMessage" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ServiceSearchBinding" type="tns:ServiceSearchPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="findTickets">
<soap:operation soapAction="" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="SearchTicketsService">
<wsdl:port name="SearchPort" binding="tns:ServiceSearchBinding">
<soap:address location="http://localhost:8080/WS1/ServiceSearchPortType" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
2) 为了生成 java 类和方法的骨架,我在我的项目名为 WS1 的文件夹中使用以下命令: /Users/Federico/apache-cxf-2.3.3/bin/wsdl2java -wsdlLocation WebContent/WSsearch.wsdl -impl -d src/ -frontend jaxws21 WebContent/WSsearch.wsdl
3) 似乎一切正常。将 web.xml 和 beans.xml 文件添加到 WEB-INF 文件夹:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/beans.xml</param-value>
</context-param>
<servlet>
<display-name>CXF Servlet</display-name>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
beans.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint
id="ricerca"
implementor="org.negozio.ServiceSearchPortTypeImpl"
address="/ServiceSearchPortType" />
</beans>
4) 现在我尝试在 WAR 中部署我的 Web 服务,将其导出到 tomcat 的 webapps 文件夹中,启动 tomcat 以在 localhost:8080/WS1 中查看我的服务的 wsdl,但我收到 404 错误,但我没有不明白为什么……
也许我写错了wsdl,或者beans.xml不正确。
我在 Eclipse 中有另一个具有相同构建路径的项目,它工作正常,所以我会排除库问题。我复制了tomcat的“lib”文件夹中的所有cxf库。
wsdl2java 自动生成的方法的个人实现是否可能会改变一些东西?
我忘记了一些段落吗?建议或解决方案? 如果您想了解更多信息或者我不清楚,请询问。 谢谢大家。
【问题讨论】:
标签: web-services tomcat wsdl cxf wsdl2java