How to pass parameter to a webservice using ksoap2?

I'm using Eclipse IDE to develop an android app. I'm trying to connect to a .net webservice. I'm using ksoap2 version 2.3

When I'm calling a webmethod with no parameters, it works fine. When I come to pass a parameter to the webmethod, I get null (while debugging the webservice I discovered that) and I get a null from the webmethod in the client side code.


package com.examples.hello;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.os.Bundle;
import android.widget.TextView;
public class HelloActivity extends Activity {
    /** Called when the activity is first created. */
 private static final String SOAP_ACTION = "http://Innovation/HRService/stringBs";

 private static final String METHOD_NAME = "stringBs";

 private static final String NAMESPACE = "http://Innovation/HRService/";
 private static final String URL = "";
 TextView tv;

 public void onCreate(Bundle savedInstanceState) {


 public void call()
         try {

          SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
          //PropertyInfo PI = new PropertyInfo();

             //request.addProperty("a", "myprop");

             SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

             envelope.encodingStyle = SoapSerializationEnvelope.XSD;

             HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

   , envelope);

             Object result = (Object)envelope.getResponse();

             String results = result.toString();
             tv.setText( ""+results); 
         } catch (Exception e) {


Why do I get the null response, how do I pass a parameter to a webservice using ksoap2?

Asked by: Rafael529 | Posted: 24-01-2022

Answer 1

Instead of

    request.addProperty("a", "myprop"); 

try using

    request.addProperty("arg0", "myprop");         

I'm not an expect on ksoap2 but i'm pretty sure this sets the value of the first parameter to your web service function. Has worked perfectly for me.

Answered by: Fenton729 | Posted: 25-02-2022

Answer 2

Calling webservice by passing parameters from j2me

SoapObject request = new SoapObject("http://www.webserviceX.NET", "GetCitiesByCountry");
String soapAction = "http://www.webserviceX.NET/GetCitiesByCountry";

request.addProperty("CountryName", "india");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.bodyOut = request;
envelope.dotNet = true;

HttpTransport ht = new HttpTransport("");
ht.debug = true;
//System.err.println( ht.requestDump );,envelope);
System.out.println("####################: " +envelope.getResponse());
//SoapObject result = (SoapObject)envelope.getResponse();

Answered by: Brianna996 | Posted: 25-02-2022

Answer 3

I have been working with this for 2 days now and i finally got the solution. I submit my complete code and hope this will help. It Can pass Parameters and get response.

Inside the WebService file in .net C#:

[WebService(Namespace = "http://something/webservice/v1")]

public DateTime[] Function(Guid organizationId, Guid categoryId)
        return ...;

Inside the Android code:

private final static String URL = "http://something/WebServices/WebService.asmx";
private final static String NAMESPACE = "http://something/webservice/v1";

public ArrayList<Object> getSoapObject(String METHOD_NAME, String SOAP_ACTION, Map<String, String> parameters){

try {

        ArrayList<Object> sol = new ArrayList<Object>();
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

        if(parameters != null){
            for (Entry<String, String> para : parameters.entrySet()) {
                request.addProperty(para.getKey(), para.getValue());

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        Log.d("Body", envelope.bodyOut.toString());

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);, envelope);
        SoapObject result=(SoapObject)envelope.getResponse();

            for(int i = 0; i < result.getPropertyCount(); i++){

            return sol;
        } catch (Exception e) {
            return null;

    public void getMenuEndDate(String orgId, String categoryId){

        Date startDate = null;
        Date endDate = null;

        HashMap<String, String> parameters = new HashMap<String, String>();
        parameters.put("organizationId", orgId);
        parameters.put("categoryId", categoryId);

        ArrayList<Object> sol = getSoapObject("Function", "http://something/webservice/v1/Function", parameters);

        SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");

        try {
            startDate = (Date)dateFormatter.parse(sol.get(0).toString());
            endDate = (Date)dateFormatter.parse(sol.get(1).toString());
        } catch (ParseException e) {
            Log.d(TAG, "Exception i Date-Formatering");


Things to check:

  • Are the parameters named exactly the same as what is expected in the Web Service?
  • Check if you use Trailing "/" for the Namespace. Have the same in you application.

Answered by: John248 | Posted: 25-02-2022

Answer 4

Try commenting out the line:


I did the same thing you did and when I read about this property being a really ugly hack, I commented it out for testing purposes and my parameter got passed correctly.

Answered by: Lily503 | Posted: 25-02-2022

Answer 5

You will have to declare parameter type in client code:

SoapObject request = new SoapObject("", "mymethod"); 
PropertyInfo p = new PropertyInfo();

Answered by: Wilson229 | Posted: 25-02-2022

Answer 6

In here Problem With the Order of Codes You Wrote, Don't Worry Try this, It's Worked for me.

private class ConversionAsyncTask extends AsyncTask<Void,Void,Void> {
    private SoapPrimitive response;
    protected Void doInBackground(Void... params) {

        SoapObject request = new SoapObject(NAMESPACE, METHOD);

        SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        soapEnvelope.dotNet = true;
        soapEnvelope.implicitTypes = true;

        try {
            HttpTransportSE aht = new HttpTransportSE(URL);
  , soapEnvelope);

            response = (SoapPrimitive) soapEnvelope.getResponse();

        } catch (Exception e) {
        return null;

    protected void onPostExecute(Void result) {
        temperatureTxt.setText("Status: " + response);

Answered by: Ada569 | Posted: 25-02-2022

Similar questions

java - Pass parameter to a webservice using ksoap2?

I have a simple web service method with a parameter like follows public String fetchOrderInfo(int g){ ... } I want to pass a value to int g from an Android program using ksoap2. I have used some thing like this but this doesn't work ... SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); PropertyInfo oId = new PropertyInfo(); oId.flags=3; oId....

web services - How to pass array of string as parameter to function in WSDL webservice from Android?

I am using WSDL web service which has a method accepting a string array as an argument. I have tried ksoap2 library but unable to find out how to pass array as an argument to that method. There are options to add parameter,values but my webservice require as an argument to function not as separate parameter,values. We can also use simple HTTP client and send a soap request as well. But I am unable to build that exact soap ...

Problem to pass parameter to a webservice using ksoap2 in Android

I have a strange problem with DotNet Service and Android (Ksoap2). I'm using this code : // Création de la requête SOAP SoapObject request = new SoapObject ("", "GetPatientWithIPPEmed"); //Ajout de propriété: addProperty(nom de variable, valeur) -&gt; Le nom de la variable vient du fichier WSDL request.addProperty("IPPEmed", Integer.parseInt("10640137...

web services - call webservice using httppost method in android with parameter

I want to call a Web-service using a Http-post method.I want to call this URL: http://serverurl/webservice/login.php?message=[{"username":"durgesh","password":"pass123"}] how to call this and how to pass parameter?

java - Pass parameter to a webservice using ksoap2?

I have a simple web service method with a parameter like follows public String fetchOrderInfo(int g){ ... } I want to pass a value to int g from an Android program using ksoap2. I have used some thing like this but this doesn't work ... SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); PropertyInfo oId = new PropertyInfo(); oId.flags=3; oId....

web services - Android webservice get out parameter

My Webservice public int GetWayBillBySachetID( int version, string encryptedJsonIn, out string encryptedJsonOut ) { // some codes return number; } Android SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, OPERATION_NAME); request.addProperty("version", "100"); request.addProperty("encryptedJsonIn", object.toStri...

Android kSOAP: Invoke WebService on SAP for complex parameter

I am trying to invoke a web service on a SAP system and am having a problem trying to pass a complex parameter in. The web service has 3 input params. 2 Strings and a complex parameter which references a SAP structure which contains several fields. These 3 input parameters are called: - Function Parameters Repid Funtion &amp; Repid are passed in ok when I invoke the web service, however, nothing is...

how to call soap webservice with large xml file as a parameter in android java

I am successfully sending string and int to soap but not xml SOAPAction: "iReceiver/XPL-CIMS-iReceiver-RecordIssuesData" &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;soap:Envelope xmlns:xsi="" xmlns:xsd="" xmlns:soap=""&gt; &lt;soap:Body&gt; &lt;XPL-CIMS-iReceiver-RecordIssuesData x...

java - Call WebService Asp.Net sending a parameter JSON

I'm trying to send a json String but when I call the WebService he send a null parameter instead of my string. When I go to Debug I can see on the soapObject Propertis my json. but in my webService i've put and when I call from my andoid app he always return null if (json.Equals(null)) { return "null"; } try { return json; root = JObject.Parse(json); } catch (Exception e) { return e.StackT...

android - how to use parameter from json webservice and retrieve json data

I'm developing an android application which will use the webservice which should accept 1 parameter from the user and based on that the value is fetched from DB(sql server 2008) and bind that to android:LISTVIEW. Without using the parameter my android application is working fine.But when i altered my webserservice to accept parameter and call it in android it is not displaying.

How to send Json String using REST to java webservice in Parameter in android?

Fiends, i sending JSON String with three parameters to java web service method. but on java side method cant print in console. Please guide me what i have to change from below code? String json = ""; HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, 10000); HttpConnectionParams.setSoTimeout(httpParams, 10000); HttpClient htt...

web services - How to make a request from an android app that can enter a Spring Security secured webservice method?

I have a Spring Security (form based authentication) web app running CXF JAX-RS webservices and I am trying to connect to this webservice from an Android app that can be authenticated on a per user basis. Currently, when I add an @Secured annotation to my webservice method all requests to this method are denied. I have tried to pass in credentials of a valid user/password (that currently exists in the Spring Security base...

android - Accessing a SOAP WebService

I have not found any convinient way to create something like a jaxws wrapperclass for an existing Soap Webservice - like in full Java. Jaxws is unfortunately not avaliable in the sdk. Is there any was to do this without using any external libs? Are there any external libs at all yet?

java - Posting a JSON array to webservice in Android

I am having some problems with what should be a rather simple task. I simply need a JSON array with a single JSON object within it to be posted to my webservice. The entire URL request needs to be formatted like this:[{"key1":"val1","key2":"val2"....}] ...

java - Call webservice from Android using KSoap simply returning "error" string

I'm trying to use ksoap to call a simple webservice. I followed this video to try to get started. When I call "getResponse()" on the envelope I just get the string "Error". There's no exceptions thrown or any other detail. I've successfully connected to a simple webservice I just setup on my local machine. Could this potentially be related to being b...

java - Parsing a JSON Response from a .Net webservice

Just to get this out in the open I am new to JAVA, KSOAP, and JSON. So I'll try to explain this the best I can. A while ago I created a webservice to be consumed by Blackberry Apps that we're built using the plug in for Visual Studio. Now the project I am working on, I want to consume the same webservice for Android devices. For the most part I have the base code for the Android app done and working. Here's my prob...

web services - Preferred Options for Webservice to Android

I need to get an Android app to interface with an XML webservice (it's really just a request which returns XML), but as the data is large and includes some things I don't need (like a huge description block), I was thinking of transforming it via a server into a format that would be good for Android, and also to be reduced considering it will be used in a low bandwidth area. Does anyone have any suggestions for a g...

web services - Android: I need to prepare the UI from the webservice

I am a newbie to Android and playing around with the UI and SQLLite for a while and it looks pretty good to me . We have a requirement that for the App that all the questions would be coming from the server through REST / Web service which would be displayed on the App.. say for e.g if there are 4 questions 1) Enter your Name -- Text Box 2) Did you sleep well last night -- YES / NO 3) How many hours did you sleep...

How to call a PHP Webservice from Android using KSOAP2?

can anybody suggest "How to call a PHP Webservice from Android using KSOAP2?"

web services - Android app using data from webservice

I want to write an Android application that can display some data received(polled) from an internet resource. I guess that I need to write some logic that will periodically call and get data from some endpoint, parse the response and display it. Is there a good tutorial for all this steps? I know very little about Android programming at the momment and maybe it is better to start with something simpler. I j...

rest webservice in android

can anybody give example of rest webservice in android

Still can't find your answer? Check out these communities...

Android Google Support | Android Community | Android Community (Facebook) | Android