Android ksoap сложный запрос - PullRequest
       16

Android ksoap сложный запрос

1 голос
/ 03 февраля 2012

Я внедряю сервис ksoap для загрузки контактов на сервер. Но я не могу использовать его успешно. Пожалуйста, если кто-нибудь может взглянуть на это и решить мою проблему. Ниже представлен формат запроса, в котором будет отправлен запрос. ...

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <testRequest xmlns="http://tempuri.org/">
      <oListDetails>
        <tblContactDetail>
          <ContactDetailID>int</ContactDetailID>
          <ContactId>int</ContactId>
          <FirstName>string</FirstName>
          <LastName>string</LastName>
          <Mobile>string</Mobile>
          <WorkPhone>string</WorkPhone>
          <Email>string</Email>
          <IM>string</IM>
          <Street>string</Street>
          <City>string</City>
          <PinCode>string</PinCode>
          <WorkCompany>string</WorkCompany>
          <JobTitle>string</JobTitle>
          <Notes>string</Notes>
          <WebSite>string</WebSite>
          <UDDI>string</UDDI>
          <Lat>string</Lat>
          <Long>string</Long>
          <AllowFollow>string</AllowFollow>
          <IsActive>boolean</IsActive>
        </tblContactDetail>
        <tblContactDetail>
          <ContactDetailID>int</ContactDetailID>
          <ContactId>int</ContactId>
          <FirstName>string</FirstName>
          <LastName>string</LastName>
          <Mobile>string</Mobile>
          <WorkPhone>string</WorkPhone>
          <Email>string</Email>
          <IM>string</IM>
          <Street>string</Street>
          <City>string</City>
          <PinCode>string</PinCode>
          <WorkCompany>string</WorkCompany>
          <JobTitle>string</JobTitle>
          <Notes>string</Notes>
          <WebSite>string</WebSite>
          <UDDI>string</UDDI>
          <Lat>string</Lat>
          <Long>string</Long>
          <AllowFollow>string</AllowFollow>
          <IsActive>boolean</IsActive>
        </tblContactDetail>
      </oListDetails>
    </testRequest>
  </soap:Body>
</soap:Envelope>

Моя основная деятельность заключается в следующем:

public class DemoAppActivity extends Activity {
    ArrayList<Information> info_array;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        soapEnvelope.encodingStyle = SoapSerializationEnvelope.XSD;
        SoapObject Request = new SoapObject("http://tempuri.org/" ,"testRequest");

        Information i1=new Information();
        i1.setContactDetailID(0);
        i1.setContactId(0);
        i1.setFirstName("James bond");
        i1.setLastName("bond");
        i1.setMobile("00000000");
        i1.setWorkPhone("00000000");
        i1.setEmail("aasa@aa.com");
        i1.setIM("aa");
        i1.setStreet("aa");
        i1.setCity("aa");
        i1.setPinCode("3333");
        i1.setWorkCompany("asada");
        i1.setJobTitle("dad");
        i1.setNotes("dsd");
        i1.setWebSite("dsds");
        i1.setUDDI("123456ewewew");
        i1.setLat("");
        i1.setLong("");
        i1.setAllowFollow("");
        i1.setIsActive(false);
        PropertyInfo pi=new PropertyInfo();
        pi.setName("oListDetails");
        pi.setValue(i1);
        pi.setType(i1.getClass());
        pi.setNamespace("http://tempuri.org/");
        Log.e("","pi===="+pi);


        Information i3=new Information();
        i3.setContactDetailID(0);
        i3.setContactId(0);
        i3.setFirstName("rajnikant");
        i3.setLastName("kant");
        i3.setMobile("111111111");
        i3.setWorkPhone("111111111");
        i3.setEmail("aa@aa.com");
        i3.setIM("aa");
        i3.setStreet("aa");
        i3.setCity("aa");
        i3.setPinCode("3333");
        i3.setWorkCompany("asada");
        i3.setJobTitle("dad");
        i3.setNotes("dsd");
        i3.setWebSite("dsds");
        i3.setUDDI("123456ewewew");
        i3.setLat("");
        i3.setLong("");
        i3.setAllowFollow("");
        i3.setIsActive(false);
        PropertyInfo pi2=new PropertyInfo();

        pi2.setName("oListDetails");
        pi2.setValue(i3);
        pi2.setType(i3.getClass());
        pi2.setNamespace("http://tempuri.org/");

        Log.e("","pi===="+pi2);
        Request.addProperty(pi);
        Request.addProperty(pi2);

        Log.e("","requset===="+Request);
        soapEnvelope.dotNet=true;
        soapEnvelope.setOutputSoapObject(Request);
        soapEnvelope.implicitTypes=true;
        soapEnvelope.addMapping("http://tempuri.org/", "oListDetails",new Information().getClass());

        AndroidHttpTransport aht = new AndroidHttpTransport("*********URL****");
        aht.debug=true;
        try
        {
            aht.call("http://tempuri.org/testRequest", soapEnvelope);

            if(soapEnvelope.getResponse()!=null){
                String input = soapEnvelope.getResponse().toString();
                Log.e("","INPUT=="+input);
            }
        }
        catch (SocketTimeoutException e) {
            Log.e("","SocketTimeoutException=="+e);
        }
        catch (SocketException e) {
            Log.e("","SocketException=="+e);
        }
        catch (XmlPullParserException e) {
            Log.e("","XmlPullParserException=="+e);
        }
        catch (SoapFault e) {
            Log.e("","SoapFault=="+e);
        }   
        catch (Exception e) {
            Log.e("","ERROR=="+e);
            e.printStackTrace();
        }

    }
}

и мой сериализуемый класс выглядит следующим образом:

package com.kran.DemoApp;

import java.util.Hashtable;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;

public class Information implements KvmSerializable{

    private int  ContactDetailID;
    private int  ContactId;
    private String FirstName;
    private String LastName;
    private String Mobile;
    private String WorkPhone;
    private String  Email;
    private String  IM;
    private String Street;
    private String City;
    private String PinCode;
    private String WorkCompany;
    private String  JobTitle;
    private String  Notes;
    private String WebSite;
    private String UDDI;
    private String Lat;
    private String Long;
    private String AllowFollow;
    private boolean IsActive;

    @Override
    public void setProperty(int arg0, Object arg1) {
        switch (arg0)
        {
        case 0:
            this.ContactDetailID = Integer.parseInt(arg1.toString());
            break;
        case 1:
            this.ContactId=Integer.parseInt(arg1.toString());
            break;
        case 2:
            this.FirstName=arg1.toString();
            break;
        case 3:
            this.LastName=arg1.toString();
            break;
        case 4:
            this.Mobile=arg1.toString();
            break;
        case 5:
            this.WorkPhone=arg1.toString();
            break;
        case 6:
            this.Email=arg1.toString();
            break;
        case 7:
            this.IM=arg1.toString();
            break;
        case 8:
            this.Street=arg1.toString();
            break;
        case 9:
            this.City=arg1.toString();
            break;
        case 10:
            this.PinCode=arg1.toString();
            break;
        case 11:
            this.WorkCompany=arg1.toString();
            break;
        case 12:
            this.JobTitle=arg1.toString();
            break;
        case 13:
            this.Notes=arg1.toString();
            break;
        case 14:
            this.WebSite=arg1.toString();
            break;
        case 15:
            this.UDDI=arg1.toString();
            break;
        case 16:
            this.Lat=arg1.toString();
            break;
        case 17:    
            this.Long=arg1.toString();
            break;
        case 18:
            this.AllowFollow=arg1.toString();
            break;
        case 19:
            this.IsActive=Boolean.parseBoolean(arg1.toString());
            break;
        default:
            break;  
        }
    }
    public int getContactDetailID() {
        return ContactDetailID;
    }
    public void setContactDetailID(int contactDetailID) {
        ContactDetailID = contactDetailID;
    }
    public int getContactId() {
        return ContactId;
    }
    public void setContactId(int contactId) {
        ContactId = contactId;
    }
    public String getFirstName() {
        return FirstName;
    }
    public void setFirstName(String firstName) {
        FirstName = firstName;
    }
    public String getLastName() {
        return LastName;
    }
    public void setLastName(String lastName) {
        LastName = lastName;
    }
    public String getMobile() {
        return Mobile;
    }
    public void setMobile(String mobile) {
        Mobile = mobile;
    }
    public String getWorkPhone() {
        return WorkPhone;
    }
    public void setWorkPhone(String workPhone) {
        WorkPhone = workPhone;
    }
    public String getEmail() {
        return Email;
    }
    public void setEmail(String email) {
        Email = email;
    }
    public String getIM() {
        return IM;
    }
    public void setIM(String iM) {
        IM = iM;
    }
    public String getStreet() {
        return Street;
    }
    public void setStreet(String street) {
        Street = street;
    }
    public String getCity() {
        return City;
    }
    public void setCity(String city) {
        City = city;
    }
    public String getPinCode() {
        return PinCode;
    }
    public void setPinCode(String pinCode) {
        PinCode = pinCode;
    }
    public String getWorkCompany() {
        return WorkCompany;
    }
    public void setWorkCompany(String workCompany) {
        WorkCompany = workCompany;
    }
    public String getJobTitle() {
        return JobTitle;
    }
    public void setJobTitle(String jobTitle) {
        JobTitle = jobTitle;
    }
    public String getNotes() {
        return Notes;
    }
    public void setNotes(String notes) {
        Notes = notes;
    }
    public String getWebSite() {
        return WebSite;
    }
    public void setWebSite(String webSite) {
        WebSite = webSite;
    }
    public String getUDDI() {
        return UDDI;
    }
    public void setUDDI(String uDDI) {
        UDDI = uDDI;
    }
    public String getLat() {
        return Lat;
    }
    public void setLat(String lat) {
        Lat = lat;
    }
    public String getLong() {
        return Long;
    }
    public void setLong(String l) {
        Long = l;
    }
    public String getAllowFollow() {
        return AllowFollow;
    }
    public void setAllowFollow(String allowFollow) {
        AllowFollow = allowFollow;
    }
    public boolean getIsActive() {
        return IsActive;
    }
    public void setIsActive(boolean isActive) {
        IsActive = isActive;
    }

    @Override
    public Object getProperty(int arg0) {
        switch (arg0) {
        case 0:
            getContactDetailID();
            break;
        case 1:
            getContactId();
            break;
        case 2:
            getFirstName();
            break;
        case 3:
            getLastName();
            break;
        case 4:
            getMobile();
            break;
        case 5:
            getWorkPhone();
            break;
        case 6:
            getEmail();
            break;
        case 7:
            getIM();
            break;
        case 8:
            getStreet();
            break;
        case 9:
            getCity();
            break;
        case 10:
            getPinCode();
            break;
        case 11:
            getWorkCompany();
            break;
        case 12:
            getJobTitle();
            break;
        case 13:
            getNotes();
            break;
        case 14:
            getWebSite();
            break;
        case 15:
            getUDDI();
            break;
        case 16:
            getLat();
            break;
        case 17:    
            getLong();
            break;
        case 18:
            getAllowFollow();
            break;
        case 19:
            getIsActive();
            break;
        default:
            break;
        }
        return null;
    }
    @Override
    public int getPropertyCount() {
        return 20;
    }


    @Override
    public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {
        switch (arg0) {
        case 0:
            arg2.type = PropertyInfo.INTEGER_CLASS;
            arg2.name = "ContactDetailID";
            break;
        case 1:
            arg2.type = PropertyInfo.INTEGER_CLASS;
            arg2.name = "ContactId";
            break;
        case 2:
            arg2.type = PropertyInfo.STRING_CLASS;
            arg2.name = "FirstName";
            break;
        case 3:
            arg2.type = PropertyInfo.STRING_CLASS;
            arg2.name = "LastName";
            break;
        case 4:
            arg2.type = PropertyInfo.STRING_CLASS;
            arg2.name = "Mobile";
            break;
        case 5:
            arg2.type = PropertyInfo.STRING_CLASS;
            arg2.name = "WorkPhone";
            break;
        case 6:
            arg2.type = PropertyInfo.STRING_CLASS;
            arg2.name = "Email";
            break;
        case 7:
            arg2.type = PropertyInfo.STRING_CLASS;
            arg2.name = "IM";
            break;
        case 8:
            arg2.type = PropertyInfo.STRING_CLASS;
            arg2.name = "Street";
            break;
        case 9:
            arg2.type = PropertyInfo.STRING_CLASS;
            arg2.name = "City";
            break;
        case 10:
            arg2.type = PropertyInfo.STRING_CLASS;
            arg2.name = "PinCode";
            break;
        case 11:
            arg2.type = PropertyInfo.STRING_CLASS;
            arg2.name = "WorkCompany";
            break;
        case 12:
            arg2.type = PropertyInfo.STRING_CLASS;
            arg2.name = "JobTitle";
            break;
        case 13:
            arg2.type = PropertyInfo.STRING_CLASS;
            arg2.name = "Notes";
            break;
        case 14:
            arg2.type = PropertyInfo.STRING_CLASS;
            arg2.name = "WebSite";
            break;
        case 15:
            arg2.type = PropertyInfo.STRING_CLASS;
            arg2.name = "UDDI";
            break;
        case 16:
            arg2.type = PropertyInfo.STRING_CLASS;
            arg2.name = "Lat";
            break;
        case 17:    
            arg2.type = PropertyInfo.STRING_CLASS;
            arg2.name = "Long";
            break;
        case 18:
            arg2.type = PropertyInfo.STRING_CLASS;
            arg2.name = "AllowFollow";
            break;
        case 19:
            arg2.type = PropertyInfo.BOOLEAN_CLASS;
            arg2.name = "IsActive";
            break;

        default:
            break;
        }


    }

}
...