CXF学习-形参、返回值为javaBean,list或数组

WS_Server:

package cxf.ws;

import java.util.List;

import javax.jws.WebService;

import cxf.ws.domain.Cat;
import cxf.ws.domain.User;

@WebService
public interface HelloWorld {
	String sayHi(String name);
	
	List<Cat> getCatByUser(User user);
}

package cxf.ws.impl;

import java.util.Date;
import java.util.List;

import javax.jws.WebService;

import cxf.ws.HelloWorld;
import cxf.ws.domain.Cat;
import cxf.ws.domain.User;
import cxf.ws.service.UserService;
import cxf.ws.service.impl.UserServiceImpl;

@WebService(endpointInterface="cxf.ws.HelloWorld",serviceName="HelloWorldWS")
public class HelloWorldWS implements HelloWorld {

	@Override
	public String sayHi(String name) {
		return name+",您好,"+"现在时间是:"+new Date();  
	}

	/**
	 * 在实际的应用中,webService只会调用业务组件,暴露接口。
	 */
	@Override
	public List<Cat> getCatByUser(User user) {
		UserService us=new UserServiceImpl();
		return us.getCatByUser(user);
	}

}


wsdl2java -frontend jaxws21  http://10.0.6.17/fightUp?wsdl
在 wsdl2java url出错时,采用的命令。


WS_Client

package lee;

import java.util.List;

import cxf.ws.Cat;
import cxf.ws.HelloWorld;
import cxf.ws.User;
import cxf.ws.impl.HelloWorldWS;

public class ClientMain {
	
	public static void main(String[] args) {
		
		HelloWorldWS  factory=new HelloWorldWS();
		
		HelloWorld hw=factory.getHelloWorldWSPort();
		
		System.out.println(hw.sayHi("孙悟空"));
		
		User user=new User();
		user.setName("Janey");
		user.setPass("202053");
		List<Cat> cats=hw.getCatByUser(user);
		//server里面带参数的构造方法在client里面没有起作用,而toString也同样不起作用。
		for(Cat cat:cats){
			System.out.println(cat.getName()+":"+cat.getColor());
		}
	}
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值