1
嗨,我想将一个类作为参数传递给Web服务。 这是我的web服务代码:作为Java中的参数传递一个类到SOAP Web服务
<xs:complexType name="RegisterStudent">
<xs:sequence>
<xs:element name="student" type="tns:student" minOccurs="0"/>
<xs:element name="user" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
这是我的我的调用函数:
public static String registerStudentClass(String user) {
soapAction="http://auth.ws.df.com/RegisterStudent";
methodName="RegisterStudent";
String resTxt = null;
Student student= new Student();
student.setAge(22);
student.setName("Jerry");
SoapObject request = new SoapObject(NAMESPACE, methodName);
request.addProperty("student", student);//Student class added here
request.addProperty("user", user);//User name, passed as string
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
System.out.println("androidHttpTransport envelope");
try{
androidHttpTransport.call(soapAction, envelope);
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
resTxt = response.toString();
}catch(Exception e){
e.printStackTrace();
resTxt = "Error occured\n"+e;
}
return resTxt;
}
这是我的学生类:
Public Class Student implements Serializable{
private int age;
private String name;
public Student(){}
public Student(int age, String name){
this.age = age;
this.name = name;
}
//setter and getter methods come here.
//...
}
后,我跑这,我得到这个错误: '无法序列化:[email protected]'Please help。
在此先感谢
'Student'是否标有'Serializable'? – kolossus
是的,请参阅编辑后 – calev