How to call webservice in Android

02 Apr

Just insert code below in your project and as per requirement add Key/Value pairs in request.addProperty. Whereas StrictMode is a developer tool which detects things you might be doing by accident and brings them to your attention so you can fix them.

StrictMode is most commonly used to catch accidental disk or network access on the application’s main thread, where UI operations are received and animations take place. Keeping disk and network operations off the main thread makes for much smoother, more responsive applications. By keeping your application’s main thread responsive, you also prevent ANR dialogs from being shown to users.

public String callGetSecurityQuestions() throws Exception{
		String NAMESPACE = "YOUR NAMESPACE HERE" //e.g. "http://namespace/";
		String URL = "YOUR URL HERE" //e.g. "http://domainname/asmx name";
		String METHOD_NAME = "YOUR METHOD NAME" //e.g. "GetSecurityQuestions";

		String response = "";
		try {
			if (android.os.Build.VERSION.SDK_INT > 9) {
				StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
			SoapObject request = new SoapObject(CommonEnviornment.NAMESPACE,METHOD_NAME);
			request.addProperty("key1", value1);			
			request.addProperty("key2", value2);
			SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
			envelope.dotNet = true;
			HttpTransportSE androidHttpTransport = new HttpTransportSE(CommonEnviornment.URL);, envelope);
			SoapObject result = (SoapObject)envelope.bodyIn;
			response = result.toString();
		} catch (Exception e) {
			throw e;
		return response;
Leave a comment

Posted by on April 2, 2014 in Android Source Code


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: