import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.HttpTransportSE; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; public class Mainactivity extends Activity { private Button ButtonCall; private static String SOAP_ACTION1 = "http://tempuri.org/HelloWorld"; private static String SOAP_ACTION2 = "http://tempuri.org/Ring"; private static String NAMESPACE = "http://tempuri.org/"; private static String METHOD_NAME1 = "HelloWorld"; private static String METHOD_NAME2 = "Ring"; private static String URL = "http://mobiletest.somee.com/Service1.asmx?WSDL"; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.my_service); ButtonCall = (Button)findViewById(R.id.button1); ButtonCall.setOnClickListener(new OnClickListener() { private TextView CallingText; public void onClick(View arg0) { //Initialize soap request + add parameters SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME2); //Use this to add parameters request.addProperty("Ringu","Ring"); //Declare the version of the SOAP request SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.setOutputSoapObject(request); envelope.dotNet = true; try { HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); //this is the actual part that will call the webservice androidHttpTransport.call(SOAP_ACTION2, envelope); // Get the SoapResult from the envelope body. SoapObject result = (SoapObject)envelope.bodyIn; if(result != null) { //Get the first property and change the label text CallingText = (TextView)findViewById(R.id.TEXTVIEW1); CallingText.setText(result.getProperty(0).toString()); } else { Toast.makeText(getApplicationContext(), "No Response",Toast.LENGTH_LONG).show(); } } catch (Exception e) { e.printStackTrace(); } } }); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)