Click here to Skip to main content
13,259,194 members (48,861 online)

How to send data from android app to web server using KSOAP

ahmed sherif shawkat asked:

Open original thread
I want to send data from the android app to the web server my code is as follows

after link the Ksoap.jar lib to my android app java build path

package com.ahmed.soapvideoservice;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity {
	String NAMESPACE = "";
    String METHOD_NAME = "GetSumOfTwoInts";
    String SOAP_ACTION = "";
    String URL = "http://localhost:51305/Service1.asmx";
    TextView tv;
    public void onCreate(Bundle savedInstanceState) {
        SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
	       PropertyInfo pi = new PropertyInfo();
	       PropertyInfo pi2 = new PropertyInfo();
	       SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
	       AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
	 , envelope);
	           SoapPrimitive result=(SoapPrimitive) envelope.getResponse();
	           tv.setText("result = "+result);
	       catch(Exception e)
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(, menu);
        return true;

and here is my web server
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace WebService1
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
        public int GetSumOfTwoInts(int Operand1, int Operand2)
            return Operand1 + Operand2;

I got an error in the android

11-14 01:59:41.150: E/dalvikvm(338): Could not find class 'org.ksoap2.serialization.SoapObject', referenced from method com.ahmed.soapvideoservice.MainActivity.onCreate
11-14 01:59:41.150: W/dalvikvm(338): VFY: unable to resolve new-instance 502 (Lorg/ksoap2/serialization/SoapObject;) in Lcom/ahmed/soapvideoservice/MainActivity;
11-14 01:59:41.150: D/dalvikvm(338): VFY: replacing opcode 0x22 at 0x0012
11-14 01:59:41.160: D/dalvikvm(338): VFY: dead code 0x0014-0087 in Lcom/ahmed/soapvideoservice/MainActivity;.onCreate (Landroid/os/Bundle;)V
11-14 01:59:41.230: D/AndroidRuntime(338): Shutting down VM
11-14 01:59:41.230: W/dalvikvm(338): threadid=1: thread exiting with uncaught exception (group=0x40015560)
11-14 01:59:41.240: E/AndroidRuntime(338): FATAL EXCEPTION: main
11-14 01:59:41.240: E/AndroidRuntime(338): java.lang.NoClassDefFoundError: org.ksoap2.serialization.SoapObject
11-14 01:59:41.240: E/AndroidRuntime(338): 	at com.ahmed.soapvideoservice.MainActivity.onCreate(
11-14 01:59:41.240: E/AndroidRuntime(338): 	at
11-14 01:59:41.240: E/AndroidRuntime(338): 	at
11-14 01:59:41.240: E/AndroidRuntime(338): 	at
11-14 01:59:41.240: E/AndroidRuntime(338): 	at$1500(
11-14 01:59:41.240: E/AndroidRuntime(338): 	at$H.handleMessage(
11-14 01:59:41.240: E/AndroidRuntime(338): 	at android.os.Handler.dispatchMessage(
11-14 01:59:41.240: E/AndroidRuntime(338): 	at android.os.Looper.loop(
11-14 01:59:41.240: E/AndroidRuntime(338): 	at
11-14 01:59:41.240: E/AndroidRuntime(338): 	at java.lang.reflect.Method.invokeNative(Native Method)
11-14 01:59:41.240: E/AndroidRuntime(338): 	at java.lang.reflect.Method.invoke(
11-14 01:59:41.240: E/AndroidRuntime(338): 	at$
11-14 01:59:41.240: E/AndroidRuntime(338): 	at
11-14 01:59:41.240: E/AndroidRuntime(338): 	at dalvik.system.NativeStart.main(Native Method)

[edit]fixed code blocks[/edit]
Tags: Mobile (Android), ASP.NET


When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).

Advertise | Privacy |
Web01 | 2.8.171114.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100