1. Download our Official Android App: Forums for Android!

Apps ASP.NET web service with ksoap2

Discussion in 'Android Development' started by bigbacon, Feb 21, 2010.

  1. bigbacon

    bigbacon Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Jan 12, 2010

    Jan 12, 2010
    5
    0
    5
    I am trying to get my app to access a .NET web service using ksoap2 and I can't get it to work. Here is my code.

    Java:
    private Object resultRequestSOAP = null;
    private static final String SOAP_ACTION = "getBaseData";
    private static final String METHOD_NAME = "getBaseData";
    private static final String NAMESPACE = "http://tempuri.org/";
    private static final String URL = "http://chadcarey.com/2142/ws2142.asmx";
    TextView tV;

    public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);

    TextView tv = ((TextView)findViewById(R.id.Tv));

    //SOAP STUFF
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);


    //SoapObject
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.setOutputSoapObject(request);
    envelope.dotNet=true;

    HttpTransport androidHttpTransport = new HttpTransport(URL);
    try
    {
    androidHttpTransport.call(SOAP_ACTION, envelope);
    resultRequestSOAP = envelope.getResponse();
    String results = (String) resultRequestSOAP;
    tv.setText(results);
    }
    catch (Exception aE)
    {
    aE.printStackTrace ();;
    }

    //SOAP STUFF



    }

    having an issue at the line "HttpTransport androidHttpTransport = new HttpTransport(URL); "

    I am not a java person so I am still learning but I have no idea what I've done wrong here. Webservice is dot.net 3.5 and I'm working with android 1.5

    Has anyone done this?? I can find TONS of examples but NO ONE to help troubleshoot this stuff....I've tried multiple other android forums already
     

    Advertisement

  2. paxel

    paxel Lurker
    Rank:
    None
    Points:
    5
    Posts:
    3
    Joined:
    Feb 17, 2010

    Feb 17, 2010
    3
    0
    5
    I'm pretty new to android development as well, but I've managed to get this working.

    Try to change
    private static final String SOAP_ACTION = "getBaseData";
    to
    private static final String SOAP_ACTION = "http://chadcarey.com/getBaseData";
    or something similar. Mine looks like this
    String SOAP_ACTION = "http://mcom.se/GetTours2";
    String METHOD_NAME = "GetTours2";
    String NAMESPACE = "http://mcom.se/";
    String URL = "http://mcom.se/TourService.asmx";

    You can also try to use a SoapPrimitive instead of an object to catch the result which means changing
    resultRequestSOAP = envelope.getResponse();
    String results = (String) resultRequestSOAP;
    to
    SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
    String resultString = result.toString();

    As I said, I'm not an expert in this field but I hope it helps
    Btw what kind of error message do you get?
    Cheers David
     
  3. bigbacon

    bigbacon Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Jan 12, 2010

    Jan 12, 2010
    5
    0
    5
    nope, still doesn't work.
    oddly enough, I don't see anything in the error log.
     
  4. paxel

    paxel Lurker
    Rank:
    None
    Points:
    5
    Posts:
    3
    Joined:
    Feb 17, 2010

    Feb 17, 2010
    3
    0
    5
    Send the error message to the textview and you should be able to read it

    tv.setText(aE.toString());
     
  5. Aselby

    Aselby Member
    Rank:
    None
    Points:
    16
    Posts:
    34
    Joined:
    Mar 29, 2010

    Mar 29, 2010
    34
    8
    16
    Indiana
    I hope you have an answer by now ... but if not

    change this line to something else

    private static final String NAMESPACE = http://tempuri.org/;
     

Share This Page

Loading...