3

I use ksoap2 to connect .NET by web service. This is my Dataset

public DataSet getphimall()
{
    DataSet ds1 = new DataSet();
    try
    {
        SqlConnection cnn = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=EMHAUI;Integrated Security=True");
        SqlCommand cmd = new SqlCommand("sp_GetAllSemester_ad", cnn);
        cmd.CommandType = CommandType.StoredProcedure;
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(ds1);
        return ds1;
    }
    catch (Exception e)
    {
        return null;
    }
}

And this is my webservice

[WebMethod]
    public DataSet getSM()
    {
        Class1 phim1 = new Class1();

        return phim1.getphimall();
    }

And this is my javaconnector class

public class getSM {
String tenphim;
String daodien;
private static final String SOAP_ACTION = "http://tempuri.org/getSM";
private static final String METHOD_NAME = "getSM";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://10.0.2.2:50532/wsAndroid.asmx";
public getSM getallphim()
{



    SoapObject table = null;                       
    SoapObject client = null;                        
    SoapObject tableRow = null;                        
    SoapObject responseBody = null;                    
    AndroidHttpTransport transport = null;            
    SoapSerializationEnvelope sse = null;
    //cái này trong tut viết thế, mình lười đổi tên


    sse = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    sse.addMapping(NAMESPACE, "getSM", this.getClass());
    sse.dotNet = true; 
    AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);

    getSM setphim = new getSM();
    try 
    {
        client = new SoapObject(NAMESPACE, METHOD_NAME);
        sse.setOutputSoapObject(client);
        sse.bodyOut = client;
        androidHttpTransport.call(SOAP_ACTION, sse);

        responseBody = (SoapObject) sse.getResponse();
        responseBody = (SoapObject) responseBody.getProperty(1);
        table = (SoapObject) responseBody.getProperty(0);
        tableRow = (SoapObject) table.getProperty(0);
        setphim.daodien = tableRow.getProperty("ID").toString();
        setphim.tenphim = tableRow.getProperty("SemesterName").toString();
        return setphim;

    } catch (Exception e) 
    {
        setphim.daodien = e.toString();
        setphim.tenphim = e.toString();
        return setphim;
    }

}}

But When I run my emulator, I have an error org.xmlpull.v1.xmlpullparserexception expected start_tag error Please help me! Thanks

user3135634
  • 33
  • 1
  • 3

1 Answers1

2

There might be a few reasons for the exception that you are getting.

  1. Wrong Parameters for the SOAP call : try to confirm if the values of NAMESPACE, ACTION, METHOD and URL are correct or not, by looking at the WSDL file
  2. Invalid response from server : try to log the response that the server sends to you and check if you are getting correct well-structured XML or not

    androidHttpTransport.debug = true;

    //execute request

    androidHttpTransport.responseDump; //response string from server

  3. dotNet attribute of the envelope : try using soapEnvelope.dotNet=true

Swayam
  • 16,294
  • 14
  • 64
  • 102
  • Thank you for your help! I think It was invalid response from server. I debugged my project. and there is error here "androidHttpTransport.call(SOAP_ACTION, sse);" I don't know how to do – user3135634 Dec 26 '13 at 08:09
  • What is the error you are getting ? And please feel free to *accept/upvote* the answer if it was helpful. :) – Swayam Dec 26 '13 at 09:20
  • I have just registered a new account. So it requires 15 reputation to up vote :-). Oh! this is my error org.xmlpull.v1.xmlpullparserexception expected start_tag – user3135634 Dec 26 '13 at 10:22
  • Oh, okay. Did you check if you are getting a valid response from the server or not ? – Swayam Dec 26 '13 at 13:54
  • I don't know how to check? :-(. Can you give me some idea? – user3135634 Dec 26 '13 at 14:35
  • I already mentioned it in my answer, under point number 2. `androidHttpTransport.debug = true; //execute request androidHttpTransport.responseDump; //response string from server` – Swayam Dec 27 '13 at 04:35
  • @PiYusHGuPtA Hello. I am just not sure if we are supposed to chat here like this. – Swayam May 28 '14 at 10:50
  • @Swayam Okay then we can chat in chat room here http://chat.stackoverflow.com/rooms/54617/developers – Piyush May 28 '14 at 10:52