nexusone nexusone - 1 month ago 13x
Java Question

how to make a ksoap2 request with multiple property in android?

I must make the following soap request, but we can not succeed, I tried in several ways and fails, I always get a blank field in response.

Request should look like this:

POST /service.asmx HTTP/1.1
Host: host
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "SOAPAction"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="" xmlns:xsd="" xmlns:soap="">
<GetQuickParkEvents xmlns="NAMESPACE">

I have this code for now:

public static Object vrati_ds(String id, String name, String username, String password, String since, String to, String reg, String korisnik, String nalog, String nameString status, String value){
SoapObject _client = new SoapObject(Konstante.NAMESPACE1, Konstante.METHOD_NAME);
_client.addProperty("ID", id);
_client.addProperty("Name", name);
_client.addProperty("UserName", username);
_client.addProperty("Password", password);
_client.addProperty("Since", since);
_client.addProperty("To", to);
_client.addProperty("Reg", reg);
_client.addProperty("Korisnik_app", korisnik);
_client.addProperty("Nalog", nalog);
_client.addProperty("Status", status);
_client.addProperty("Value", value);
SoapSerializationEnvelope _envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
_envelope.dotNet = true;
HttpTransportSE _ht = new HttpTransportSE(Konstante.URL1);, _envelope);
return _envelope.getResponse();
} catch(Exception e) {
return null;

I thank you in advance if anyone can help me!


For now I hardcoded xml request manually, so if anyone can help, here are the source code which works:

public static Object getEvent2(int id, String name, String username, String password, String since, String to, 
        String reg, String nalog, String status, String value ) throws Exception {

    String response= null;
    String xml = null;

    HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(Konstante.URL);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.encodingStyle = SoapSerializationEnvelope.ENC;

    String bodyOut = "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"\" xmlns:xsd=\"\" xmlns:soap=\"\">";
    bodyOut += "<soap:Body><"+Konstante.EVENS_METHOD_NAME+" xmlns=\"" + Konstante.NAMESPACE + "\">";
    bodyOut += "<User><ID>" + id + "</ID><Name>" + name + "</Name><UserName>";
    bodyOut += username + "</UserName><Password>" + password + "</Password></User>";
    bodyOut += "<Filter><TimeSpan><Since>" + since + "+02:00" + "</Since><To>" + to + "+02:00" +"</To></TimeSpan>";
    bodyOut += "<Reg>" + reg + "</Reg><Nalog>" + nalog + "</Nalog><Status>" + status + "</Status><Value>" + value + "</Value></Filter>";
    bodyOut += "</"+Konstante.EVENS_METHOD_NAME+"></soap:Body></soap:Envelope>";

    xml = bodyOut;

    StringEntity se = new StringEntity(xml, HTTP.UTF_8);
    httpPost.addHeader(Konstante.EVENS_SOAP_ACTION, Konstante.URL);

    HttpResponse httpResponse = httpClient.execute(httpPost);
    HttpEntity resEntity = httpResponse.getEntity();
    response = EntityUtils.toString(resEntity);

    return response;