1. Check out our app, Forums for Android! Download and leave feedback here!

ASP.NET web service with ksoap2

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

  1. bigbacon

    bigbacon Member
    Thread Starter
    5

    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 New Member
    5

    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 Member
    Thread Starter
    5

    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 New Member
    5

    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 Active Member
    16

    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...