[webservice] 12_webservice传输自定义实体对象

Android 4.0

webservice传输自定义实体对象

实体对象,和内置对象的传输差不多,
只是在传输的过程中,服务器发送过来时,会将实体对象用xml的标签来表示,
数据传递到客户端时,客户端又会重新的解析服务器传送过来的xml文件的数据

下面是服务器传送过来的符合soap协议的xml数据
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
        <ns2:findPersonByIdCardResponse
            xmlns:ns2="http://ws.itcast.cn/">
            <return>
                <age>10</age>
                <idCard>007</idCard>
                <name>zhagnsan</name>
            </return>
        </ns2:findPersonByIdCardResponse>
    </S:Body>
</S:Envelope>
server:
package cn.itcast.ws;
 
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
 
import cn.itcast.domain.Person;
 
@WebService
public class PersonService {
 
    /**
     * 根据身份证号查询人员信息
     */

    public Person findPersonByIdCard(String idCard){
        Person p = new Person();
        p.setIdCard(idCard);
        p.setName("zhagnsan");
        p.setAge(10);
        return p;
    }
 
    public static void main(String[] args) {
        Endpoint.publish("http://localhost:9876/person", new PersonService());
        System.out.println("personService ready...");
    }
}
client:
package cn.itcast.ws;
public class App {
    public static void main(String[] args) {
        PersonServiceService pss = new PersonServiceService();
        PersonService ps = pss.getPersonServicePort();
        Person person = ps.findPersonByIdCard("001");
        System.out.println(person);
    }
}