Currently i am consuming web service from android by the method SOAP.Here i need to call the webservice and return the result on android/eclipse.ie.I need to get the input from edittext and return the appropriate value.
Please find my code for reference.
web method
public class GetName {
public String GetName(String a){
return(a);
} }
NOTE: To avoid socket operation exceptions from main activity thread,i have written a separate classes and isolate soap related functions.
Caller.java
public class Caller extends Thread
{
public AlertDialog ad;
public CallSoap cs;
public int a;
public void run()
{
try
{
cs=new CallSoap();
String resp=cs.Call(a);
MySOAPCallActivity.rslt=resp;
}catch(Exception ex)
{
MySOAPCallActivity.rslt=ex.toString();
}
} }
CallSOAP
public class CallSoap
{
public final String SOAP_ACTION = "http://tempuri.org/GetName";
public final String OPERATION_NAME = "GetName";
public final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
public final String SOAP_ADDRESS = "http://122.248.240.105:234/Service1.asmx?WSDL";
public CallSoap()
{
}
public String Call(int a)
{
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
PropertyInfo pi=new PropertyInfo();
pi.setName("a");
pi.setValue(a);
pi.setType(Integer.class);
request.addProperty(pi);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
Object response=null;
try
{
httpTransport.call(SOAP_ACTION, envelope);
response = envelope.getResponse();
}
catch (Exception exception)
{
response=exception.toString();
}
return response.toString();
}
}
MySOAPCallActivity
public class MySOAPCallActivity extends Activity
{
public static String rslt="";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button b1=(Button)findViewById(R.id.btn_getvalues);
final AlertDialog ad=new AlertDialog.Builder(this).create();
b1.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
try
{
EditText ed1=(EditText)findViewById(R.id.et_1);
String ed1str = ed1.getText().toString().trim();
int a = Integer.parseInt(ed1str);
rslt="START";
Caller c=new Caller();
c.a=a;
c.ad=ad;
c.join();
c.start();
while(rslt=="START")
{
try
{
Thread.sleep(5);
}catch(Exception ex)
{
}
}
ad.setTitle("");
ad.setMessage(rslt);
}catch(Exception ex)
{
ad.setTitle("Error!");
ad.setMessage(ex.toString());
}
ad.show();
}
});
} }
OUTPUT SCREEN

Note: If I enter the vlaue “0005” it must return the String “Vivek” in browser.
But in my output screen it shown as “Name not found”.I wanna to return the appropriate value as per the users input.Please let me know how to mend my source.
Thanks for your precious time!..
Please use my experience. I think it will help you. I had lot of troubles while doing the same task. But finally i did the thing as given in the blog. http://www.insightforfuture.blogspot.com/search/label/Android