JAX-WS(四)webservice传递对象
使用webservice传递对象
接口
package com.hqh.service;import javax.jws.WebParam;import javax.jws.WebResult;import javax.jws.WebService;@WebServicepublic interface IMyService {@WebResult(name="plusResult")public int plus(@WebParam(name="a")int a,@WebParam(name="b")int b);@WebResult(name="minusResult")public int minus(@WebParam(name="a")int a,@WebParam(name="b")int b);//返回一个User对象@WebResult(name="User")public User getUser(@WebParam(name="username")String uname,@WebParam(name="age")int age);}
package com.hqh.service;import javax.jws.WebService;@WebService(endpointInterface="com.hqh.service.IMyService")//endpointInterface 接入点接口public class MyServiceImpl implements IMyService {@Overridepublic int plus(int a, int b) {System.out.println("MyServiceImpl.plus()");return a+b;}@Overridepublic int minus(int a, int b) {System.out.println("MyServiceImpl.minus()");return a-b;}@Overridepublic User getUser(String uname, int age) {User user = new User(uname,age);user.setId(100);return user;}}
<?xml version="1.0"?><xs:schema version="1.0" targetNamespace="http://service.hqh.com/"> <xs:element name="getUser" type="tns:getUser"/> <xs:element name="getUserResponse" type="tns:getUserResponse"/> <!--方法入参--> <xs:complexType name="getUser"> <xs:sequence> <xs:element name="username" type="xs:string" minOccurs="0"/> <xs:element name="age" type="xs:int"/> </xs:sequence> </xs:complexType> <!--返回值定义--> <xs:complexType name="getUserResponse"> <xs:sequence> <!--定义返回类型--> <xs:element name="User" type="tns:user" minOccurs="0"/> </xs:sequence> </xs:complexType> <!--返回类型的详细信息:User对象属性--> <xs:complexType name="user"> <xs:sequence> <xs:element name="age" type="xs:int"/> <xs:element name="id" type="xs:int"/> <xs:element name="uname" type="xs:string" minOccurs="0"/> </xs:sequence> </xs:complexType></xs:schema>