使用webservice传递对象
接口
package com.hqh.service; import javax.jws.WebParam; import javax.jws.WebResult; import javax.jws.WebService; @WebService public 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 { @Override public int plus(int a, int b) { System.out.println("MyServiceImpl.plus()"); return a+b; } @Override public int minus(int a, int b) { System.out.println("MyServiceImpl.minus()"); return a-b; } @Override public User getUser(String uname, int age) { User user = new User(uname,age); user.setId(100); return user; } }
wsdl中的对象传递
<?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>