Click here to Skip to main content
16,019,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Here Is My Code Below "This doesn't work"
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.VER12);
		    	
		    	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();
		    	}
			}
		});
	
 
}
Posted

How To Call Web Service In Android ?
Look here:
Step by Step Method to Access Webservice from Android[^]
How to Call Web Service in Android Using SOAP[^]

For more, look here.[^]
 
Share this answer
 
Comments
ali4050 21-Oct-12 6:39am    
Thanks For your Help But It Doesn't Work
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900