Closed GoogleCodeExporter closed 8 years ago
When you want to pass object of a class to webservice as agrument of a method .
And all class you want to transfer to web service must be serializable.
So,
- You must:
+create a class implement from KvmSerializable class and implement base method as needed to tell for Ksoap know how to serialize your class.
+ If class member variable have type as a class .It must be serializable.
+ Finally. using addMapping method of SoapSerializationEnvelope to add your class to ksoap to can transfer it throught wweb service.
Example:
I have a class call Account:
public class Account
{
private String mUser;
private String mPass;
private NoteType note;
}
and NoteType is my class :
public class NoteType {
private String mSubject;
private String mText;
}
--> I want to transert Account object to web service throught function :
bool signIn(Account acc) ( web service method )
I must change:
public class NoteType implements KvmSerializable{
private String mSubject;
private String mText;
public NoteType(){
this.setSubject("");
this.setText("");
}
public NoteType(String s,String t){
this.setSubject(s);
this.setText(t);
}
@Override
public Object getProperty(int index) {
switch(index)
{
case 0:
return this.getSubject();
case 1:
return this.getText();
}
return null;
}
@Override
public int getPropertyCount() {
return 2;
}
@Override
public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
switch(index)
{
case 0:
info.name="subject";
info.type=PropertyInfo.STRING_CLASS;
break;
case 1:
info.name="text";
info.type=PropertyInfo.STRING_CLASS;
break;
}
}
@Override
public void setProperty(int index, Object value) {
switch(index)
{
case 0:
this.setSubject(value.toString());
break;
case 1:
this.setText(value.toString());
break;
}
}
public void setSubject(String mSubject) {
this.mSubject = mSubject;
}
public String getSubject() {
return mSubject;
}
public void setText(String mText) {
this.mText = mText;
}
public String getText() {
return mText;
}
}
public class Account implements KvmSerializable
{
private String mUser;
private String mPass;
private NoteType note;
public NoteType getNote() {
return note;
}
public void setNote(NoteType note) {
this.note = note;
}
public Account()
{
this.setUser("");
this.setPass("");
}
public Account(String u,String p)
{
this.setUser(u);
this.setPass(p);
}
public String getUser() {
return mUser;
}
public void setUser(String user) {
this.mUser = user;
}
public String getPass() {
return mPass;
}
public void setPass(String pass) {
this.mPass = pass;
}
@Override
public Object getProperty(int propertyID) {
switch(propertyID)
{
case 0:
return this.getUser();
case 1:
return this.getPass();
case 2:
return this.getNote();
}
return null;
}
@Override
public int getPropertyCount() {
return 3;
}
/**
* This is form of class in server ,
* so properties must same with sever.
*/
@Override
public void getPropertyInfo(int propertyID, Hashtable arg1, PropertyInfo info) {
switch(propertyID)
{
case 0:
info.name="user";
info.type=PropertyInfo.STRING_CLASS;
break;
case 1:
info.name="pass";
info.type=PropertyInfo.STRING_CLASS;
break;
case 2:
info.name="note";
info.type=NoteType.class;
break;
}
}
@Override
public void setProperty(int propertyID, Object value) {
switch(propertyID)
{
case 0:
this.setUser(value.toString());
break;
case 1:
this.setPass(value.toString());
break;
case 2:
this.setNote(value);
break;
}
}
}
And when i call using SoapSerializationEnvelope , HttpTransportSE :
SoapSerializationEnvelope envelope = new
SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.addMapping(S_NAMESPACE, "Account",Account.class);
envelope.addMapping(S_NAMESPACE, "NoteType",NoteType.class);
// Here i call
Original comment by tauit.d...@gmail.com
on 9 Nov 2011 at 3:10
Thanks. It is working fine.
Original comment by manishos...@gmail.com
on 10 Nov 2011 at 6:23
Wrong usage. Not an issue.
Original comment by mosa...@gmail.com
on 18 Nov 2011 at 4:31
Original issue reported on code.google.com by
manishos...@gmail.com
on 9 Nov 2011 at 1:17