Problem while calling the web services in android.
To call web services in android I have done the following steps
1. Wrote the web service class in java and stored in apache axis.
(in .jws format)
public class ADD2No
{
public int add(int a,int b)
{
return (a+b);
}
public int sub(int c,int d)
{
return (c-d);
}
}
2. Then is have tested the web service on web browser.
http://192.168.1.41:8081/axis/ADD2No.jws
I have got.
There is a Web Service here
Click to see the WSDL
in browser.
3. then I implement the service using core java and Ksoap2 library.
Its working fine.
4. But I got error when I call the web service via android.
5. This is my code.
package com.example.SamWebService;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class WebServiceInAndroid extends Activity
{
/** Called when the activity is first created. */
/*
private static final String SOAP_ACTION = "HelloYou";
private static final String METHOD_NAME = "getHello";
private static final String NAMESPACE = "urn:HelloYou";
private static final String URL = "http://localhost/lab/
service.php";
*/
private static final String SOAP_ACTION = "ADD2No";
private static final String METHOD_NAME = "add";
private static final String NAMESPACE = "urn:ADD2No";
private static final String URL = "http://elcserver:8081/axis/
ADD2No.wsdl";
//private Object resultsRequestSOAP = null;
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
TextView tv = (TextView) findViewById(R.id.txt1);
setContentView(R.layout.main);
try
{
SoapObject request = new SoapObject(NAMESPACE,
METHOD_NAME);
request.addProperty("a", 3);
request.addProperty("b", 4);
SoapSerializationEnvelope envelope = new
SoapSerializationEnvelope(SoapEnvelope.VER11);
//envelope.dotNet = true;
envelope.setOutputSoapObject(request);
AndroidHttpTransport androidHttpTransport = new
AndroidHttpTransport(URL);
try
{
androidHttpTransport.call(SOAP_ACTION,
envelope);
//Parse Response
SoapObject resultsRequestSOAP = (SoapObject)
envelope.bodyIn;
//String xy = resultsRequestSOAP.getProperty
(0).toString();
tv.setText("Ganzes Rückagbeobjekt:
\n"+resultsRequestSOAP.toString());
}
catch (Exception e)
{
e.printStackTrace();
}
}
catch(Exception e)
{
tv.setText("Error : " + e.getMessage());
}
}
}
6. I have tried lot of methods still I am getting the error.
“Your application has been stopped unexpectedly”
7. my application’s manifest file is
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.SamWebService"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/
app_name">
<activity android:name=".WebServiceInAndroid"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission xmlns:android="http://schemas.android.com/apk/res/
android" android:name="android.permission.INTERNET"></uses-permission>
<uses-sdk android:minSdkVersion="3" />
</manifest>
8. So give me solutions to overcome this problem and how to define the
SOAP_NAME, METHOD_NAME, NAMESPACE and URL what they meant really.
9. Give me the step by step procedure to call apache axis web services
from android.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---