Java WebService-CXF-基于SOAP的Web服务

Java WebService-CXF

基于SOAP的Web服务

[email protected]

2015年12月11日

 

1  目标:使用XML进行网络交互通信,提供WEB服务,RPC的进化版。

2 原理:使用XML协议进行Http通信交互,使用JAX-WS进行XML与Java服务交互,Java Bean提供服务。

3  流程:基于SOAP的 Web服务

注意:SOAP需要提供Http Body作为参数,方法调用时只能使用Post调用,无法使用Get调用。

参考:http://www.coderanch.com/t/638206/Web-Services/java/Calling-Soap-JAX-WS-http

3.1 基于SOAP的Web服务:安装CXF库,配置web.xml,配置Spring,创建WebService的服务Bean。

3.1.1创建Dynamic Web Project。

3.1.2安装CXF库(自带Spring库):下载CXF,解压后将lib下所有内容copy到web-inf/lib下。将库加入ClassPath。

Eclipse中有CXF的Runtime库(?)

3.1.3配置web.xml:指定Spring为Web监听类,设置CXF的Servlet。

//web.xml

<?xmlversion="1.0" encoding="UTF-8"?>

<web-appxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://xmlns.jcp.org/xml/ns/javaee"xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"id="WebApp_ID" version="3.1">

 <display-name>CXFDemo</display-name>

    <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>

    </servlet>

    <servlet-mapping>

        <servlet-name>CXFServlet</servlet-name>

        <url-pattern>/services/*</url-pattern>

    </servlet-mapping>

</web-app>

3.1.4配置Spring:添加jaxws命名空间,设置endpoint。

Spring配置详情参见:JavaEE-Spring.docx

//applicationContext.xml

<?xmlversion="1.0" encoding="UTF-8"?>

<beansxmlns="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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd

http://cxf.apache.org/jaxwshttp://cxf.apache.org/schemas/jaxws.xsd">

      <import resource="classpath:META-INF/cxf/cxf.xml"/>

      <importresource="classpath:META-INF/cxf/cxf-extension-soap.xml" />

      <importresource="classpath:META-INF/cxf/cxf-servlet.xml" />

      <jaxws:endpointid="webServiceHelloWorld" address="/HelloWorld"

           implementor="lee.HelloWorldImpl"/>

</beans>

3.1.5创建WebService的服务Bean类:使用@WebService标记。

//IHelloWorld.java

package lee;

 

import javax.jws.WebMethod;

import javax.jws.WebService;

 

@WebService

public interface IHelloWorld{

           @WebMethod

           String say(String msg);

           @WebMethod

           String sayHello();

}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

弗里曼的小伙伴

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值