Note that there are some explanatory texts on larger screens.

plurals
  1. POCall the web service and return the result on Android/Eclipse by SOAP method
    primarykey
    data
    text
    <p>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.</p> <p>Please find my code for reference.</p> <p><strong>web method</strong></p> <pre><code>public class GetName { public String GetName(String a){ return(a); } } </code></pre> <p><strong>NOTE:</strong> To avoid socket operation exceptions from main activity thread,i have written a separate classes and isolate soap related functions.</p> <p><strong>Caller.java</strong></p> <pre><code>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(); } } } </code></pre> <p><strong>CallSOAP</strong></p> <pre><code>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(); } } </code></pre> <p><strong>MySOAPCallActivity</strong></p> <pre><code>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(); } }); } } </code></pre> <p><strong>OUTPUT SCREEN</strong></p> <p><img src="https://i.stack.imgur.com/fPr4u.jpg" alt="enter image description here"></p> <p><strong>Note:</strong> If I enter the vlaue <strong>"0005"</strong> it must return the String <strong>"Vivek"</strong> in browser.</p> <p>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.</p> <p>Thanks for your precious time!..</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload