Problem while calling the web services in android.

2 replies [Last post]
karthick
User offline. Last seen 2 years 26 weeks ago. Offline
Joined: 08/06/2009

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"?>

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.

pandorauk
User offline. Last seen 1 year 8 weeks ago. Offline
Joined: 12/07/2010
it is sometimes world of hard

it is sometimes world of hard to Pandora in a world of adults Pandora Bracelets

bousherif
User offline. Last seen 11 weeks 5 days ago. Offline
Joined: 07/27/2011
Subject of a wonderful and

Subject of a wonderful and unique and deserves thanks
العاب اكشن