码迷,mamicode.com
首页 > Web开发 > 详细

webservice 从入门到精通(二)helloworld(Webservice + cxf)

时间:2021-06-02 19:21:52      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:out   rri   技术   port   设置   小明   pac   ima   server   

1  官网下jar包,搭工程(略)

http://cxf.apache.org/

 

2 代码 

package com.mangoubiubiu.cxf.test;

import javax.jws.WebService;

@WebService //对外发布服务
public interface HelloWorld {

	public String sayHello(String name);
	
}

 

package com.mangoubiubiu.cxf.test;

import javax.jws.WebService;

public class HelloWorldImpl implements HelloWorld {

	@Override
	public String sayHello(String name) {
		return "cxf1022"+name;
	}

}

3 服务端发布(服务端放实现类

package com.mangoubiubiu.cxf.test;

import org.apache.cxf.endpoint.Server;
import org.apache.cxf.jaxws.JaxWsClientFactoryBean;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;

public class MainServer {
    
    public static void main(String args[]){
        
        JaxWsServerFactoryBean jaxWsServerFactoryBean=new JaxWsServerFactoryBean();
        
        jaxWsServerFactoryBean.setAddress("http://127.0.0.1:9999/cxf1022_server");
        
        jaxWsServerFactoryBean.setServiceClass(HelloWorldImpl.class);
        Server server=    jaxWsServerFactoryBean.create();
        server.start();
    }

}

4 访问WSDL

http://127.0.0.1:9999/cxf1022_server?wsdl

技术图片

 

 

5 客户端调用(客户端放接口

package com.mangoubiubiu.cxf.test;

import org.apache.cxf.endpoint.Server;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;

public class ClientServer {

    public static void main(String args[]){
        
    
        
        // TODO Auto-generated method stub
        //创建调用服务的类...
        JaxWsProxyFactoryBean bean=new JaxWsProxyFactoryBean();
        //设置访问地址
        bean.setAddress("http://127.0.0.1:8888/cxf1022_server");
        //设置接口类型...
        bean.setServiceClass(HelloWorld.class);
        HelloWorld us=(HelloWorld) bean.create();
        
        String data=us.sayHello("小明");
        
        System.out.println(data);
    }
    
}

 

webservice 从入门到精通(二)helloworld(Webservice + cxf)

标签:out   rri   技术   port   设置   小明   pac   ima   server   

原文地址:https://www.cnblogs.com/mangoubiubiu/p/14833520.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!