Java > service
CXF 不支持 RPC/encoding 风格. RPC/literal 是WS-l BP 中定义的, 唯一一种能够用于互操作的.
CXF 有多种运行方式, 以下描述, 依赖 Servlet容器和 spring 的运行方式.
JAX-WS = JAX-RPC 2.0
web.xml
<context-param> <param-name>contextConfigLocation</param-name> <param-value>WEB-INF/services.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <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>/service/*</url-pattern> </servlet-mapping>
service.xml
<?xml version="1.0"?> <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 spring-beans-2.5.xsd http://cxf.apache.org/jaxws 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="ap" implementor="hi.HiImpl" address="/hi" /> </beans>
Hi.java
package hi; import javax.jws.WebService; @WebService public interface Hi { String sayHi(String text); }
HiImpl.java
package hi; import javax.jws.WebService; @WebService(endpointInterface = "hi.Hi") public class HiImpl implements Hi { public String sayHi(String msg) { return "Hi " + msg; } }
dependencies in maven's pom.xml
<dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> <version>2.5.6</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-frontend-jaxws</artifactId> <version>2.2.8</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http</artifactId> <version>2.2.8</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http-jetty</artifactId> <version>2.2.8</version> <type>jar</type> <scope>compile</scope> </dependency> </dependencies>
附件提供一个可运行的例子. 字符行下进入项目目录, 运行 mvn package jetty:run, 浏览器打开 http://localhost:8080/service 即可看到服务列表.
默认生成的服务是 document/literal 风格的
enjoy it! that's all
wsdl > service
to be continue
--- --- ---
Ref
http://www.ibm.com/developerworks/cn/webservices/ws-spec/
http://www.ibm.com/developerworks/cn/webservices/understand/
http://www.ibm.com/developerworks/cn/webservices/ws-tip-jaxwsrpc.html
关于 java的 很多问题 都可以在 Spec中找到解答! http://jcp.org/ 问题之源也是答案所在