CXF调用webservices

阅读更多

如何实现调用Webservice

一、准备工作

1、按文档搭建新建平台项目,配置数据库
2
、确认pom中是否引入maven依赖,没有的话,请引入。


    org.apache.cxf
    cxf-rt-frontend-jaxws
    2.3.2


    org.apache.cxf
    cxf-rt-transports-http
    2.3.2

 

 

二、实现步骤

 

(一)调用webservice

 

1如果调用的是由java发布的webservice,且能拿到接口文件,推荐使用这种方式调用

 

HelloWorldClient.java

不要忘记引入接口jar

 

1.package com.test.client;

2.

3.

4.import org.springframework.context.ApplicationContext;

5.import org.springframework.context.support.ClassPathXmlApplicationContext;

6.

7.

8.import com.test.server.IHelloWorldServer;

9.

10.

11.publicclass HelloWorldClient {

12.publicstaticvoid main(String[] args) {

13.

14. ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-client.xml");

15.//如果在项目中跑,这里可以自动注入,不用手动去取

16. IHelloWorldServer helloService = (IHelloWorldServer) context.getBean("client");

17. String response = helloService.sayHello("jialin");

18. System.out.println(response);

19. }

20.

21.

22.}

 


applicationContext-client.xml

 

[html]view plaincopyprint?

 

1.xmlversion="1.0"encoding="UTF-8"?>

2.<beansxmlns="http://www.springframework.org/schema/beans"

3.xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

4.xmlns:jaxws="http://cxf.apache.org/jaxws"

5.xsi:schemaLocation="http://www.springframework.org/schema/beans

6. http://www.springframework.org/schema/beans/spring-beans.xsd

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

8.

你可能感兴趣的:(CXF调用webservices)