Advertisement
kusha45

Web service

Aug 11th, 2011
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. //WEB SERVICE
  2.  
  3. <WebMethod()> _
  4. Public Function Hello(ByVal strText As String) As String
  5. Return "Hello " + strText
  6. End Function
  7.  
  8. //Android CODE
  9.  
  10. package com.tt;
  11.  
  12. import android.app.Activity;
  13. import android.os.Bundle;
  14. import android.view.View;
  15. import android.view.View.OnClickListener;
  16. import android.widget.Button;
  17. import android.widget.EditText;
  18. import android.widget.TextView;
  19.  
  20. import org.ksoap2.SoapEnvelope;
  21. import org.ksoap2.serialization.PropertyInfo;
  22. import org.ksoap2.serialization.SoapObject;
  23. import org.ksoap2.serialization.SoapSerializationEnvelope;
  24. import org.ksoap2.transport.AndroidHttpTransport;
  25.  
  26. public class TrialconActivity extends Activity {
  27.  
  28. private static final String SOAP_ACTION = "http://tempuri.org/Hello";
  29. private static final String METHOD_NAME = "Hello";
  30. private static final String NAMESPACE = "http://tempuri.org";
  31. private static final String URL ="http://192.168.75.8/Web%20Service/Service1.asmx";
  32.  
  33. public TrialconActivity(){}
  34.  
  35. Object result = null;
  36. EditText ed1;
  37. TextView password,tv1,tv2;
  38. Button click;
  39.  
  40. @Override
  41. public void onCreate(Bundle savedInstanceState) {
  42. super.onCreate(savedInstanceState);
  43. setContentView(R.layout.main);
  44.  
  45. tv1 = (TextView)findViewById(R.id.textView1);
  46. ed1 = (EditText)findViewById(R.id.eduser);
  47. click = (Button)findViewById(R.id.button1);
  48.  
  49. click.setOnClickListener(new OnClickListener() {
  50. @SuppressWarnings("deprecation")
  51. @Override
  52. public void onClick(View v) {
  53. try{
  54. SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
  55.  
  56. password = (TextView)findViewById(R.id.edpass);
  57.  
  58. String data = password.getText().toString();
  59. System.out.println("The String is :"+data);
  60.  
  61. request.addProperty("strText", data);
  62.  
  63. SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
  64.  
  65. envelope.dotNet = true;
  66.  
  67. envelope.setOutputSoapObject(request);
  68.  
  69. AndroidHttpTransport aht=new AndroidHttpTransport(URL);
  70.  
  71. aht.call(SOAP_ACTION, envelope);
  72.  
  73. result = envelope.getResponse();
  74.  
  75. String ans = result.toString();
  76.  
  77. ed1.setText(ans);
  78. }
  79. catch(Exception e){
  80. tv1.setText(e.toString());
  81. }
  82. }
  83. });
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement