1. Check out our companion app, Forums for Android! Download from Google Play

Android client using .Net web service

Discussion in 'Application Development' started by paxel, Feb 17, 2010.

  1. paxel

    paxel New Member
    Thread Starter
    5

    Feb 17, 2010
    3
    0
    5
    Hi
    Recently I have been trying to connect to a .Net web service using a Android App. I've tried various tutorials but none of them have worked so far.

    The code got so far
    private String[] getViewedTours(String city) {
    String SOAP_ACTION = "http://mcom.se/GetTours2";
    String METHOD_NAME = "GetTours2";
    String NAMESPACE = "http://mcom.se/";
    String URL = "http://mcom.se/TourService.asmx";
    String[] tours = new String[100];
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

    PropertyInfo pi = new PropertyInfo();
    pi.setName("location");
    pi.setValue(city);
    request.addProperty(pi);
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);

    AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);

    try
    {
    androidHttpTransport.call(SOAP_ACTION, envelope);

    SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
    String tourString = result.toString();
    }
    catch (Exception e) {}

    It works as long as I don't uses the parameters, but as soon as I add the parameters the application throws a java.lang.classcastexception: org.ksoap2.serialization.soapobject exception.

    The code for the web service is

    public string GetTours2(string loc)
    {
    ........
    DataSet myDataSet = new DataSet();
    myDataAdapter.Fill(myDataSet, "mytable");
    DataTable dt = myDataSet.Tables[0];

    string tourid = "";
    for (int i = 0; i < dt.Rows.Count; i++)
    {
    DataRow dr = dt.Rows;
    tourid += (int)dr["id"] + " ";
    }
    return tourid;
    }

    It would be nice if anyone could take a look at this, because i'm so stuck at the moment.
    Cheers David
     

    Advertisement

Share This Page

Loading...