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

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

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

 

 

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)

上一篇:MVC、MVP和MVVM的区别


下一篇:jquery页面水印插件,支持多行水印、行错开