How to send data from android app to asp.net web server using KSOAP
Revision 1
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.app.Activity;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity {
String NAMESPACE = "http://vladozver.org/";
String METHOD_NAME = "GetSumOfTwoInts";
String SOAP_ACTION = "http://vladozver.org/GetSumOfTwoInts";
String URL = "http://localhost:51305/Service1.asmx";
TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv=(TextView)findViewById(R.id.textView1);
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo pi = new PropertyInfo();
pi.setName("Operand1");
pi.setValue(2);
pi.setType(int.class);
Request.addProperty(pi);
PropertyInfo pi2 = new PropertyInfo();
pi2.setName("Operand2");
pi2.setValue(5);
pi2.setType(int.class);
Request.addProperty(pi2);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(Request);
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
try
{
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive result=(SoapPrimitive) envelope.getResponse();
tv.setText("result = "+result);
}
catch(Exception e)
{
e.printStackTrace();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
and here is my asp.net web server
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace WebService1
{
[WebService(Namespace = "http://vladozver.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
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(MainActivity.java:29)
11-14 01:59:41.240: E/AndroidRuntime(338): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-14 01:59:41.240: E/AndroidRuntime(338): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
11-14 01:59:41.240: E/AndroidRuntime(338): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
11-14 01:59:41.240: E/AndroidRuntime(338): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-14 01:59:41.240: E/AndroidRuntime(338): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
11-14 01:59:41.240: E/AndroidRuntime(338): at android.os.Handler.dispatchMessage(Handler.java:99)
11-14 01:59:41.240: E/AndroidRuntime(338): at android.os.Looper.loop(Looper.java:123)
11-14 01:59:41.240: E/AndroidRuntime(338): at android.app.ActivityThread.main(ActivityThread.java:3683)
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(Method.java:507)
11-14 01:59:41.240: E/AndroidRuntime(338): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-14 01:59:41.240: E/AndroidRuntime(338): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-14 01:59:41.240: E/AndroidRuntime(338): at dalvik.system.NativeStart.main(Native Method)
Posted 13-Nov-12 13:02pm
by
ahmed sherif shawkat.