• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps ASP.NET web service with ksoap2

bigbacon

Lurker
Jan 12, 2010
5
0
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
 
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
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones