1.基本类型

–int,float,boolean等

2.引用类型

–String

–集合:数组,List, Set, Map

–自定义类型   Student


服务端

javaBean

package com.me.ws.bean;

public class Person {
private Integer id;
private String name;
private Integer age;

public Person() {

}

public Person(Integer id, String name, Integer age) {
super();
this.id = id;
this.name = name;
this.age = age;
}

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Integer getAge() {
return age;
}

public void setAge(Integer age) {
this.age = age;
}

@Override
public String toString() {
return "Person [id=" + id + ", name=" + name + ", age=" + age + "]";
}

}


SEI接口

package com.me.ws2;

import java.util.List;
import java.util.Map;

import javax.jws.WebMethod;
import javax.jws.WebService;

import com.me.ws.bean.Person;

/*
* SEI
*/
@WebService
public interface PersonWS {
@WebMethod
public boolean addPerson(Person person);

@WebMethod
public Person getPersonById(int id);
@WebMethod
public List<Person> getPersonList(int age);
@WebMethod
public Map<Integer,Person> getAllPersonsMap();
}



SEI接口实现类


package com.me.ws2;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.jws.WebService;

import com.me.ws.bean.Person;

/*
* SEI的实现
*/
@WebService
public class PersonWSImpl implements PersonWS {

@Override
public boolean addPerson(Person person) {
System.out.println("addPerson(Person person)"+person.toString());
return true;
}

@Override
public Person getPersonById(int id) {
// TODO Auto-generated method stub
return new Person(id, "小明", 20);
}

@Override
public List<Person> getPersonList(int age) {
List<Person> list = new ArrayList<>();
list.add(new Person(1, "tom", 20));
list.add(new Person(2, "tom2", 20));
list.add(new Person(3, "tom3", 20));
return list;
}

@Override
public Map<Integer, Person> getAllPersonsMap() {
Map<Integer, Person> map = new HashMap<>();
map.put(1, new Person(1, "jack1", 12));
map.put(2, new Person(2, "jack2", 12));
map.put(3, new Person(3, "jack3", 12));
return map;
}



}


发布服务

package com.me.ws.server;

import javax.xml.ws.Endpoint;

import com.me.ws2.PersonWSImpl;

/*
* 发布Web Service
*/
public class ServerTest {
public static void main(String[] args) {


String address = "http://192.168.1.104:8787/cxf/personWS";
Endpoint.publish(address, new PersonWSImpl());
System.out.println("发布webservice成功!");
}
}


使用cxf工具包生成客户端代码

测试CXF支持的数据类型_java

客户端测试代码

package com.me.ws.test;

import java.util.List;

import com.me.ws2.GetAllPersonsMapResponse.Return;
import com.me.ws2.GetAllPersonsMapResponse.Return.Entry;
import com.me.ws2.Person;
import com.me.ws2.PersonWS;
import com.me.ws2.PersonWSImplService;

public class ClientTest2 {
public static void main(String[] args) {
PersonWSImplService factory = new PersonWSImplService();
PersonWS personWS = factory.getPersonWSImplPort();

boolean flag = personWS.addPerson(new Person(10,1,"jack"));
System.out.println(flag);

Person person = personWS.getPersonById(1);
System.out.println(person);

List<Person> personList = personWS.getPersonList(2);
System.out.println(personList);

Return result = personWS.getAllPersonsMap();
List<Entry> entrys = result.getEntry();
for (Entry entry : entrys) {
System.out.println("id="+entry.getKey()+entry.getValue());

}

}
}