Привет Я хочу передать класс как параметр веб-службе. Это мой код веб-сервис:Передача класса веб-службе SOAP в качестве параметра в Java
<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]». Пожалуйста, помогите.
Заранее спасибо
«Ученик» отмечен символом 'Serializable'? – kolossus
Да см. Отредактированный пост – calev