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

Android Applicatin consuming ASP.NET Web Service

Hi!

I'we written a simple Android java application consuming an ASP.NET web service. But it throws the error message "java.net.ConnectException: localhost/127.0.0.1:8080 - Connection refused" when doing
androidHttpTransport.call(SOAP_ACTION, envelope). Can this error be related to the Network Connections configuration in Eclipse, or any IIS configuration? Here's the code:
(By the way, IIS is runnig, I can reach http://localhost:8080/erkService.asmx and make request, get response wtih internet browser. Get message returns ony a string without taking any input parameter)


package
com.wsImpl;

import​

​

org.ksoap2.SoapEnvelope;
import​

​

org.ksoap2.serialization.SoapObject;
import​

​

org.ksoap2.serialization.SoapSerializationEnvelope;
import​

​

org.ksoap2.transport.HttpTransportSE;

import​

​

android.app.Activity;
import​

​

android.os.Bundle;
import​

​

android.widget.ArrayAdapter;
import​

​

android.widget.AutoCompleteTextView;

public​

​

class ErkActivity extends Activity {

privatestaticfinal String NAMESPACE = "http://artisinerji.com/";
privatestaticfinal String URL = "http://localhost:8080/erkService.asmx?wsdl";​

​
​
privatestaticfinal String SOAP_ACTION = "http://artisinerji.com/GetMessage"; ​

privatestaticfinal String METHOD_NAME = "GetMessage";​


@Override
publicvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);​

setContentView(R.layout.main); ​

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);​


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

envelope.setAddAdornments(false);​


​
​
HttpTransportSE androidHttpTransport = ​

​

new HttpTransportSE(URL);



try {​

androidHttpTransport.call(SOAP_ACTION, envelope);​


​
​
SoapObject response = (SoapObject) envelope.​

​

bodyIn;
String result = response.toString();​

} catch (Exception e) {
e.printStackTrace();
}​

}​
}



​
 
Hi,

Thank you very much for your reply. I've changed the URL, now it is so:
http://192.168.5.68:8080/erkService.asmx. Connection is OK now, and I can even work this link in the browser of the emulator and see the web service methods. But I'm receiving another error when I run the code: "
org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://www.w3.org/2001/12/soap-envelope}Envelope (position:START_TAG <{http://schemas.xmlsoap.org/soap/envelope/}soap:Envelope>@1:207 in java.io.InputStreamReader@4052e9d0)
"
It cannot parse the wsdl document anyway. I didn't find any useful entry for my situation over internet but go on researching. Have you got any idea?


 
Hi again,


I solved the issue. I had changed "VER11" to "VER12" in creating the envelope. I rechanged it again to VER11 and now it works, I can get the response from GetMessage method. The last version of the code is below.


Thank you.



package​
​
​
​
​
com.wsImpl;
​

import​
​
​
​
​
org.ksoap2.SoapEnvelope;
​

import​
​
​
​
​
org.ksoap2.serialization.SoapObject;
​

import​
​
​
​
​
org.ksoap2.serialization.SoapSerializationEnvelope;
​

import​
​
​
​
​
org.ksoap2.transport.HttpTransportSE;
​

import​
​
​
​
​
android.app.Activity;
​

import​
​
​
​
​
android.os.Bundle;
​

import​
​
​
​
​
android.widget.ArrayAdapter;
​

import​
​
​
​
​
android.widget.AutoCompleteTextView;
​

public​
​
​
​
​
class ErkActivity extends Activity {

private static final String NAMESPACE = "http://artisinerji.com";

private static final String URL = "http://192.168.5.68:8080/erkService.asmx";

private static final String SOAP_ACTION = "http://artisinerji.com/GetMessage";

private static final String METHOD_NAME = "GetMessage";

private static final String[] sampleACTV = new String[] { "android",

"iphone", "blackberry" };

@Override​

​
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.
main);

ArrayAdapter<String> arrAdapter =
new ArrayAdapter<String>(this,

android.R.layout.
simple_dropdown_item_1line, sampleACTV);

AutoCompleteTextView ACTV = (AutoCompleteTextView) findViewById(R.id.
AutoCompleteTextView01);

ACTV.setAdapter(arrAdapter);

SoapObject request =
new SoapObject(NAMESPACE, METHOD_NAME);

SoapSerializationEnvelope envelope =
new SoapSerializationEnvelope(

SoapEnvelope.
VER11);

envelope.
dotNet = true;

envelope.setOutputSoapObject(request);

envelope.setAddAdornments(
false);

HttpTransportSE androidHttpTransport =
new HttpTransportSE(URL);

try {

androidHttpTransport.call(
SOAP_ACTION, envelope);

SoapObject response = (SoapObject) envelope.
bodyIn;

String result = response.getProperty(0).toString();

ACTV.setHint(
"Received :" + result);

}
catch (Exception e) {

e.printStackTrace();

ACTV.setHint(
"An Error Occured:" + e.getMessage());

}

}

}
​

 
Hi,
I am new to android, and trying to consume a dot net webservice as stated in your steps.

But I am not able to use the web service.
and when I run the application it gives error:

Sorry!
The application websertest (process com.websertest ) has stopped unexpectedly. Please try again.

please help

Thanks in advance

 
Back
Top Bottom