你好我已经使用ksoap了很长一段时间了,而且这一次我收到了复杂对象的数组。现在我需要发送一个我试了一个星期但是我无法管理它。我猜测是复杂的对象没有在服务器端正确映射。我已经发现了我正在使用数据包嗅探器发送的消息。我认为命名空间和映射有问题。让我发布你我的意思到目前为止。网络服务是wcf所以我也会发给你wcftestclient的soap消息,以及我从我的android应用程序发送的内容。
public class MainActivity extends Activity {
private Button btn;
private Button btn1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
btn=(Button) findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
SoapObject soapObjectRequest = new SoapObject("http://microsoft.com/webservices/","InsertStudentAbsences");
SRV_Students_Absence objStudentAbsences = new SRV_Students_Absence();
PropertyInfo propertyInfo = new PropertyInfo();
propertyInfo.setName("objStudentAbsences");
propertyInfo.setType(SRV_Students_Absence.class);
propertyInfo.setValue(objStudentAbsences);
PropertyInfo propertyInfo1 = new PropertyInfo();
propertyInfo1.setName("connString");
propertyInfo1.setType(String.class);
propertyInfo1.setValue("server=verl,1524;Database=olDB;UID=sa;Password=7Esta#KAz");
soapObjectRequest.addProperty(propertyInfo1);
soapObjectRequest.addProperty(propertyInfo);
soapObjectRequest.addProperty("Company","8");
soapObjectRequest.addProperty("Lng","00");
soapObjectRequest.addProperty("MainPeriod","80");
soapObjectRequest.addProperty("UserID","14453");
soapObjectRequest.addProperty("CourseDate","2012-11-06");
SoapSerializationEnvelope soapSerializationEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapSerializationEnvelope.dotNet = true;
soapSerializationEnvelope.implicitTypes = true;
soapSerializationEnvelope.setOutputSoapObject(soapObjectRequest);
soapSerializationEnvelope.addMapping(soapObjectRequest.getNamespace(), "SRV_Students_Absence", objStudentAbsences.getClass());
//soapSerializationEnvelope.addMapping(soapObjectRequest.getNamespace(), "SRV_Absence_Category", SRV_Absence_Category.class);
//soapSerializationEnvelope.addMapping("http://schemas.datacontract.org/2004/07/WcfService_StudentGrades", "SRV_Student", SRV_Student.class);
try {
/**
* Mail the letter.
*/
HttpTransportSE httpTransportSE = new HttpTransportSE("http://androidwcf.schoolportal.gr");
httpTransportSE.call("http://microsoft.com/webservices/"+"IVertiSchool_SRV/InsertStudentAbsences", soapSerializationEnvelope);
httpTransportSE.debug=true;
SoapObject soapObjectResponse = (SoapObject)soapSerializationEnvelope.getResponse();
} catch (Exception exception) {
exception.printStackTrace();
}
}
});
}
这是实现KvmSerializable的类:
public class SRV_Students_Absence implements KvmSerializable {
private int AbCode;
private String AbNum;
private int AbsCatID;
private String ActID;
private String Cause;
private int ClCode;
private int CoCode;
private String CompanyCode;
private String CourseDate;
private boolean Flag;
private String InsDate;
private int InsWay;
private String IsParentsInf;
private String IsVerified;
private String LngCode;
private String MainPeriod;
private String SmsFlag;
private int StuCode;
private int TimeCode;
private String UserIdName;
private String WPCID;
private String WPGID;
private SRV_Student objAC;
private SRV_Absence_Category objStudent;
public SRV_Students_Absence(){
AbCode= 0;
AbNum= null;
AbsCatID= 421;
ActID= null;
Cause= null;
ClCode= 375;
CoCode= 7628;
CompanyCode= "8";
CourseDate= "11/6/2012 9:50 AM";
Flag=false;
InsDate=null;
InsWay=3;
IsParentsInf=null;
IsVerified=null;
LngCode="00";
MainPeriod=null;
SmsFlag=null;
StuCode=1359;
TimeCode=1963;
UserIdName=null;
WPCID=null;
WPGID=null;
objAC=null;
objStudent=null;
}
@Override
public Object getProperty(int arg0) {
System.out.println("arxh");
switch (arg0) {
case 0:
System.out.println(">0");
return AbCode;
case 1:
System.out.println("1");
return AbNum;
case 2:
System.out.println("2");
return AbsCatID;
case 3:
System.out.println("3");
return ActID;
case 4:
System.out.println("4");
return Cause;
case 5:
System.out.println("5");
return ClCode;
case 6:
System.out.println("6");
return CoCode;
case 7:
System.out.println("7");
return CompanyCode;
case 8:
System.out.println("8");
return CourseDate;
case 9:
System.out.println("9");
return Flag;
case 10:
System.out.println("10");
return InsDate;
case 11:
System.out.println("11");
return InsWay;
case 12:
System.out.println("12");
return IsParentsInf;
case 13:
System.out.println("13");
return IsVerified;
case 14:
System.out.println("14");
return LngCode;
case 15:
System.out.println("15");
return MainPeriod;
case 16:
System.out.println("16");
return SmsFlag;
case 17:
System.out.println("17");
return StuCode;
case 18:
System.out.println("18");
return TimeCode;
case 19:
System.out.println("19");
return UserIdName;
case 20:
System.out.println("20");
return WPCID;
case 21:
System.out.println("21");
return WPGID;
case 22:
System.out.println("22");
return objAC;
case 23:
System.out.println("23");
return objStudent;
default:break;
}
return 005;
}
@Override
public int getPropertyCount() {
return 24;
}
@Override
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo info) {
switch (arg0) {
case 0:
System.out.println(":D "+arg0);
info.type = PropertyInfo.INTEGER_CLASS;
info.name = "AbCode";
break;
case 1:
System.out.println(":D "+arg0);
info.type = PropertyInfo.STRING_CLASS;
info.name = "AbNum";
break;
case 2:
System.out.println(":D "+arg0);
info.type = PropertyInfo.INTEGER_CLASS;
info.name = "AbsCatID";
break;
case 3:
System.out.println(":D "+arg0);
info.type = PropertyInfo.STRING_CLASS;
info.name = "ActID";
break;
case 4:
System.out.println(":D "+arg0);
info.type = PropertyInfo.STRING_CLASS;
info.name = "Cause";
break;
case 5:
System.out.println(":D "+arg0);
info.type = PropertyInfo.INTEGER_CLASS;
info.name = "ClCode";
break;
case 6:
System.out.println(":D "+arg0);
info.type = PropertyInfo.INTEGER_CLASS;
info.name = "CoCode";
break;
case 7:
System.out.println(":D "+arg0);
info.type = PropertyInfo.STRING_CLASS;
info.name = "CompanyCode";
break;
case 8:
System.out.println(":D "+arg0);
info.type = PropertyInfo.STRING_CLASS;
info.name = "CourseDate";
break;
case 9:
System.out.println(":D "+arg0);
info.type = PropertyInfo.BOOLEAN_CLASS;
info.name = "Flag";
break;
case 10:
System.out.println(":D "+arg0);
info.type = PropertyInfo.STRING_CLASS;
info.name = "InsDate";
break;
case 11:
System.out.println(":D "+arg0);
info.type = PropertyInfo.INTEGER_CLASS;
info.name = "InsWay";
break;
case 12:
System.out.println(":D "+arg0);
info.type = PropertyInfo.STRING_CLASS;
info.name = "IsParentsInf";
break;
case 13:
System.out.println(":D "+arg0);
info.type = PropertyInfo.STRING_CLASS;
info.name = "IsVerified";
break;
case 14:
System.out.println(":D "+arg0);
info.type = PropertyInfo.STRING_CLASS;
info.name = "LngCode";
break;
case 15:
System.out.println(":D "+arg0);
info.type = PropertyInfo.STRING_CLASS;
info.name = "MainPeriod";
break;
case 16:
System.out.println(":D "+arg0);
info.type = PropertyInfo.STRING_CLASS;
info.name = "SmsFlag";
break;
case 17:
System.out.println(":D "+arg0);
info.type = PropertyInfo.INTEGER_CLASS;
info.name = "StuCode";
break;
case 18:
System.out.println(":D "+arg0);
info.type = PropertyInfo.INTEGER_CLASS;
info.name = "TimeCode";
break;
case 19:
System.out.println(":D "+arg0);
info.type = PropertyInfo.STRING_CLASS;
info.name = "UserIdName";
break;
case 20:
System.out.println(":D "+arg0);
info.type = PropertyInfo.STRING_CLASS;
info.name = "WPCID";
break;
case 21:
System.out.println(":D "+arg0);
info.type = PropertyInfo.STRING_CLASS;
info.name = "WPGID";
break;
case 22:
System.out.println(":D "+arg0);
info.type = SRV_Absence_Category.class;
info.name = "objAC";
break;
case 23:
System.out.println(":D "+arg0);
info.type = SRV_Student.class;
info.name = "objStudent";
break;
default:break;
}
}
@Override
public void setProperty(int arg0, Object value) {
System.out.println("setting Property");
switch (arg0) {
case 0:
AbCode = Integer.parseInt(value.toString());
case 1:
AbNum = value.toString();
case 2:
AbsCatID=(Integer.parseInt(value.toString()));
case 3:
ActID = value.toString();
case 4:
Cause = value.toString();
case 5:
ClCode = Integer.parseInt(value.toString());
case 6:
CoCode = Integer.parseInt(value.toString());
case 7:
CompanyCode= value.toString();
case 8:
CourseDate = value.toString();
case 9:
Flag = Boolean.getBoolean(value.toString());
case 10:
InsDate = value.toString();
case 11:
InsWay = Integer.parseInt(value.toString());
case 12:
IsParentsInf = value.toString();
case 13:
IsVerified = value.toString();
case 14:
LngCode = value.toString();
case 15:
MainPeriod = value.toString();
case 16:
SmsFlag = value.toString();
case 17:
StuCode = Integer.parseInt(value.toString());
case 18:
TimeCode = Integer.parseInt(value.toString());
case 19:
UserIdName = value.toString();
case 20:
WPCID = value.toString();
case 21:
WPGID= value.toString();
case 22:
objAC= null;
case 23:
objStudent= null;
}
}
}
如果你有任何相关经验给我一个方向,我真的很喜欢。
谢谢你的时间。