Home » Android » android – JSON String returned from SOAP web service containing no records for table

android – JSON String returned from SOAP web service containing no records for table

Posted by: admin May 14, 2020 Leave a comment


I have a SOAP web service(.asmx) implemented using the .NET framework that returns me a JSON String in this form:


Now in my Android app I am using ksoap to call the web service in the following way:

    public String getjsondata(String b)

     String be=""; 

        SoapObject request = new SoapObject(namespace, method_NAME);      

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
        envelope.dotNet = true; 

        HttpTransportSE  android = new HttpTransportSE(url);

        android.debug = true; 


    //android.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");   
    android.call(soap_ACTION, envelope);

    SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
    System.out.println(" --- response ---- " + result); 

    if (be.startsWith("[")) 
    { // if JSON string is an array
        JSONArr = new JSONArray(be);

        System.out.println("length" + JSONArr.length());
        for (int i = 0; i < JSONArr.length(); i++) 
            JSONObj = (JSONObject) JSONArr.get(i);
            bundleResult.putString(String.valueOf(i), JSONObj.toString());
            System.out.println("bundle result is"+bundleResult);


    catch (SocketException ex) { 
    } catch (Exception e) { 

    return be;      


I am getting a response but the response doesn’t contain any records and shows blank values.

Here is response from Logcat:

 11-21 20:13:03.283: INFO/myapp(1173): {"checkrecord":[],"Table1":[]}

 11-21 20:13:03.283: INFO/System.out(1173):  --- response ---- {"checkrecord":[],"Table1":[]}

Can anyone tell me why is this happening?

My web service code :

      using System;
      using System.Collections;
      using System.ComponentModel;
      using System.Data;
      using System.Linq;
      using System.Web;
      using System.Web.Services;
      using System.Web.Services.Protocols;
      using System.Xml.Linq;
      using System.Data.SqlClient;

namespace returnjson
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService

    public String getdata(String rollno)
        String json;

            using (SqlConnection myConnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=student;User ID=sa;Password=123"))

           string select = "select * from checkrecord where rollno=\'" + rollno + "\'";
                SqlDataAdapter da = new SqlDataAdapter(select, myConnection);
                DataSet ds = new DataSet();
                da.Fill(ds, "checkrecord");
                DataTable dt = new DataTable();
                json = Newtonsoft.Json.JsonConvert.SerializeObject(ds);


        catch (Exception ex)
            return null;


        return json;



Edit: I have tested my web service code using a client app on .NET and it is working fine..getting a proper response as per returned JSON String with all records and values.

How to&Answers:

It’s seem this problem relate to some specific symbol like : \ lead to soap parse error.

you can use some tool like Ethereal to analyzer the input stream and make sure you have received correctly. if it’s right, may be you should encode you json data and then send it.

I just test it on my server(lamp)which return a JSONObject in body,and android use below code,work normally:

public static void testApi() {
        AndroidHttpTransport androidHttptt = new AndroidHttpTransport("");
        SoapObject request = new SoapObject(NAMESPACE, "check_error");
        // request.addProperty("data", "empty");
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        Element[] header = new Element[1];
        header[0] = new Element().createElement(NAMESPACE, "Credentials");
        envelope.dotNet = true;
        envelope.headerOut = header;

        AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(url);
        try {
            androidHttptt.call("", envelope);
            SoapObject response = (SoapObject) envelope.getResponse();
            Log.e("response", "response=" + response.toString());
        } catch (Exception e) {


with Etheral,I get the data like this:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<ns1:check_errorResponse xmlns:ns1="http://test.test.com">
<Result xsi:type="xsd:string">{&quot;checkrecord&quot;:[{&quot;rollno&quot;:&quot;abc2&quot;,&quot;percentage&quot;:40,&quot;attended&quot;:12,&quot;missed&quot;:34}],&quot;Table1&quot;:[]}</Result>

You can find the json data have been convered to



SOAP protocol uses XML as means of communication. Your Request will be converted to a XML String and the response from the server will be a XML String which the KSOap parses and gives you an Object.
So it looks like the response from WebService is fine but there is a problem with KSoap parsing. So as you guys were discussing you can encode the String in the server and return it.
Android already provides support for Base64 encoding/decoding.

In the webservice return the following instead of json.

Convert.ToBase64String (Encoding.UTF8.GetBytes (json));

This will return you an encoded string. So the response you will get be an encoded string. So in the android client side.

new String(android.util.Base64.decode(responseString.getBytes(),android.util.Base64.DEFAULT))

which will give u the decoded string.Hope it helps