Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi!

I have an Android app consuming asp.net web services. It works fine when I call asp.net ws that requires no parameter passing.

But another asp.net ws requires parameter passing, and I send the parameters, but it receives the parameters as null values. I debugged and saw that Android app send the parameters correctly. Asp.net ws takes parameters as null values, and send the response back without taking these variables into account.

The Android app code:



Java
package com.wsImpl;

import org.apache.http.client.HttpClient;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope ;
import org.ksoap2.transport.AndroidHttpTransport;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class ErkActivity7
      extends Activity {

   private static final String NAMESPACE =
         "http://artisinerji.com";
   private static final String URL =
         "http://192.168.5.68:8080/erkService.asmx";
   private static final String SOAP_ACTION =
         "http://artisinerji.com/GetSumOfTwoInts";
   private static final String METHOD_NAME =
         "GetSumOfTwoInts";

   private static final String[] sampleACTV =
         new String[] { "android", "iphone", "blackberry" };

   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);

      ArrayAdapter<String> arrAdapter =
            new ArrayAdapter<String>(this,
                  android.R.layout.simple_dropdown_item_1line,
                  sampleACTV);

		AutoCompleteTextView ACTV =
		      (AutoCompleteTextView) findViewById(
                            R.id.AutoCompleteTextView01);
		ACTV.setAdapter(arrAdapter);

		SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

		int num1 = 3; int num2 = 5;
		request.addProperty("num1",num1);
		request.addProperty("num2",num2);

		SoapSerializationEnvelope envelope = 
		      new SoapSerializationEnvelope(SoapEnvelope.VER11);

		envelope.dotNet = true;
		envelope.setOutputSoapObject(request);
		envelope.setAddAdornments(true);

		AndroidHttpTransport androidHttpTransport = 
		      new AndroidHttpTransport(URL);

		try {
		   androidHttpTransport.call(SOAP_ACTION, envelope);
		   SoapObject response = (SoapObject) envelope.bodyIn;

		   String result = response.getProperty(0).toString();
		   ACTV.setHint("Receivedddd: " + result.toString());
		} 
		catch (Exception e) {
		   e.printStackTrace();
		   ACTV.setHint("An Error Occured:" + e.getMessage());
		}

	}

}
Posted
Updated 26-Aug-22 6:14am
v4
Comments
TorstenH. 21-Jun-11 4:25am    
added some format. Do you write this on a mobile? Why was the code that narrow formated?
Nagy Vilmos 21-Jun-11 5:19am    
Second go at formatting ;)

Have you only tried this on the emulator, if so check the manifest.xml and make sure

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

is set. I read that when using the emulator this type of action is silent.

Hope it helps

Darren

Edit: Also perhaps take a look at Step by Step Method to Access Webservice from Android[^] here on CP
 
Share this answer
 
v2
Comments
Nagy Vilmos 23-Jun-11 8:48am    
Good answer.
Hi I have this problem too....i connot pass parametter to .net ws... did you already solved?
 
Share this answer
 
Did you find the solution , I'm facing the same problem ???
 
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