![]()
![]()
![]()
package com.rl.cxf.client;
import com.rl.inter.HI;
import com.rl.inter.HIService;
public class HiInterClient {
public static void main(String[] args) {
HIService hiService = new HIService();
//返回的服务的实现类使用接口接收
HI hi = hiService.getHIPort();
String result = hi.sayHi("王五");
System.out.println(result);
}
}
package com.rl.cxf.inter;
import javax.jws.WebService;
@WebService
public interface HI {
public String sayHi(String name);
}
package com.rl.cxf.inter;
public class HIImpl implements HI{
@Override
public String sayHi(String name) {
// TODO Auto-generated method stub
return name+ " hi";
}
}
package com.rl.cxf.server;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
import com.rl.cxf.inter.HI;
import com.rl.cxf.inter.HIImpl;
public class MyCXFServerInter {
public static void main(String[] args) {
//创建服务工厂对象
//ServerFactoryBean sfb = new ServerFactoryBean();
JaxWsServerFactoryBean sfb = new JaxWsServerFactoryBean();
//加入输入输出拦截器
sfb.getInInterceptors().add(new LoggingInInterceptor());
//sfb.getOutFaultInterceptors().add(new LoggingOutInterceptor());
sfb.getOutInterceptors().add(new LoggingOutInterceptor());
//指定服务地址
sfb.setAddress("http://127.0.0.1:9999/hi");
//设置接口
sfb.setServiceClass(HI.class);
//设置接口实现类
sfb.setServiceBean(new HIImpl());
//发布服务
sfb.create();
System.out.println("server ready...");
}
}