我已经编辑了示例,并为您添加了新的完整示例,我认为它可以为您提供帮助。在此示例中,我在服务器端数据库中有一个客户表,并且我想通过KvmSerializable用户定义的类将数据从android插入到此表中。这是
KvmSerializable用户为用户定义的类:
public class Customer implements KvmSerializable {public int Customer_ID;public String Customer_Name;public String Customer_Family;public Customer() {}public Customer(int customer_id, String customer_name, String customer_family) { Customer_ID = customer_id; Customer_Name = customer_name; Customer_Family = customer_family;}public Object getProperty(int arg0) { // TODO Auto-generated method stub switch (arg0) { case 0: return Customer_ID; case 1: return Customer_Name; case 2: return Customer_Family; } return null;}public int getPropertyCount() { // TODO Auto-generated method stub return 25;}public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) { // TODO Auto-generated method stub switch (index) { case 0: info.type = PropertyInfo.INTEGER_CLASS; info.name = "Customer_ID"; break; case 1: info.type = PropertyInfo.STRING_CLASS; info.name = "Customer_Name"; break; case 2: info.type = PropertyInfo.STRING_CLASS; info.name = "Customer_Family"; break; default: break; }}public void setProperty(int index, Object value) { // TODO Auto-generated method stub switch (index) { case 0: Customer_ID = Integer.parseInt(value.toString()); break; case 1: Customer_Name = value.toString(); break; case 2: Customer_Family = value.toString(); break; default: break; }}}
现在,为客户提供了c#用户定义的类:
public class Customer { public int Customer_ID; public string Customer_Name; public string Customer_Family; }
这是
CallSoap我
KvmSerializable为此定义的用于发送对象的类:
public class CallSoap {public static String NAMESPACE = "http://127.0.0.1:80/";public static String URL = "http://127.0.0.1:80/service.asmx?WSDL";public static Customer[] customers;public static int AddCustomer(Customer[] customers) { String MethodName = "AddCustomer"; SoapObject soapAddCustomer = new SoapObject(NAMESPACE, MethodName); //customers Parameter SoapObject soapDetails = new SoapObject(NAMESPACE, "customers"); SoapObject soapDetail[] = new SoapObject[customers.length]; for (int i=0;i<customers.length;i++){ soapDetail[i]= new SoapObject(NAMESPACE, "Customer"); soapDetail[i].addProperty("Customer_ID", customers[i].Customer_ID); soapDetail[i].addProperty("Customer_Name", customers[i].Customer_Name); soapDetail[i].addProperty("Customer_Family", customers[i].Customer_Family); } soapAddRequest.addSoapObject(soapDetails); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(soapAddRequest); envelope.addMapping(NAMESPACE, "Customer", new Customer().getClass()); HttpTransportSE HttpTransportSE = new HttpTransportSE(URL); try { HttpTransportSE.call(NAMESPACE + MethodName, envelope); String result = envelope.getResponse().toString(); return Integer.parseInt(result); } catch (Exception e) { e.printStackTrace(); return 0; }}
最后是
AddCustomer服务器端的方法:
[WebMethod]public int AddCustomer(Customer[] customers){ for(int i=0;i<customers.Length;i++){ //Access to customer fields for allrows via int id = customers[i].Customer_ID; String name = customers[i].Customer_Name; String = customers[i].Customer_Family; } return customers.Length;}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)