apache的cxf框架发布与调用WebService

1.服务端

    1.1    创建web工程

    1.2    引入jar包

    1.3    在web.xml中配置cxfServlet,并引入cxf配置文件

            <servlet>
          <servlet-name>cxf</servlet-name>
          <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
          <init-param>
          <param-name>config-location</param-name>
          <param-value>classpath:cxf.xml</param-value>
          </init-param>
          </servlet>
          <servlet-mapping>
          <servlet-name>cxf</servlet-name>
          <url-pattern>/service/*</url-pattern>
          </servlet-mapping>

    1.4     在classpath下配置cxf.xml文件

            <?xml version="1.0" encoding="UTF-8"?>
            <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:soap="http://cxf.apache.org/bindings/soap"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/bindings/soap 
http://cxf.apache.org/schemas/configuration/soap.xsd
http://cxf.apache.org/jaxws 
http://cxf.apache.org/schemas/jaxws.xsd">
<!-- 引入CXF Bean定义如下,早期的版本中使用 -->
<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" />

<bean id="MyServcie" class="MyServiceImpl"/>

<!-- 注册服务 -->
<jaxws:server id="myService" address="/cxfService">
<jaxws:serviceBean>
<ref bean="MyServcie"/>
</jaxws:serviceBean>
</jaxws:server>

</beans>

1.4    创建interface接口,并创建实现类,启动服务器发布发布服务


2.客户端

    2.1    创建工程

    2.1.1   引入jar包

    2.2    调用java的wsimport或cxf的我受到了wsdl2java 解析wsdl的xml文件生成类

    2.3    复制接口到创建的工程

    2.4    配置cxf.xml文件

        <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:soap="http://cxf.apache.org/bindings/soap"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/bindings/soap 
http://cxf.apache.org/schemas/configuration/soap.xsd
http://cxf.apache.org/jaxws 
http://cxf.apache.org/schemas/jaxws.xsd">
<!-- 引入CXF Bean定义如下,早期的版本中使用 -->
<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" />

<!-- 注册CXF客户端代理对象,通过spring框架创建这个代理对象,使用代理对象实现远程调用 -->
<jaxws:client id="myClient" 
address="http://127.20.10.3:8080/cxfServerTets/service/cxfService" 
serviceClass="MyServcie">
</jaxws:client>

</beans>

2.5    启动工程,加载cxf.xml文件,获取接口实现类,调用服务.

          ApplicationContext ac = new ClassPathXmlApplicationContext("cxf.xml");
MyServcie ms = (MyServcie) ac.getBean("myClient");
String a = ms.sayHello("yangyang", 30);
System.out.println(a);


    

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值