I am implenting java web services for android project and calling with KSOAP2.
My Code is mention below..
package com.android.service;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MyAndroidService extends Activity {
private static final String NAMESPACE = "http://project.com/";
private static final String METHOD_NAME = "sayHello";
String SOAP_ACTION = "http://project.com/sayHello";
private static final String URL =
"http://localhost:8080/MyProject/wsdl/Hello.wsdl";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv=(TextView)findViewById(R.id.text);
try{
SoapObject object=new SoapObject(NAMESPACE, METHOD_NAME);
object.addProperty("name", "dev");
SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(object);
HttpTransportSE httpTransportSE=new HttpTransportSE(URL);
httpTransportSE.call(SOAP_ACTION, envelope);
Object result=envelope.getResponse();
System.out.println("result :"+result.toString());
}catch (Exception e) {
System.out.println(e);
}
}
}
ただし、以下でも言及されている拡張機能を常に取得しています
08-28 17:32:18.378: E/AndroidRuntime(6739): FATAL EXCEPTION: main
08-28 17:32:18.378: E/AndroidRuntime(6739): java.lang.NoClassDefFoundError: org.ksoap2.serialization.SoapObject
08-28 17:32:18.378: E/AndroidRuntime(6739): at com.android.service.MyAndroidService.onCreate(MyAndroidService.java:24)
08-28 17:32:18.378: E/AndroidRuntime(6739): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-28 17:32:18.378: E/AndroidRuntime(6739): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-28 17:32:18.378: E/AndroidRuntime(6739): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-28 17:32:18.378: E/AndroidRuntime(6739): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-28 17:32:18.378: E/AndroidRuntime(6739): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-28 17:32:18.378: E/AndroidRuntime(6739): at android.os.Handler.dispatchMessage(Handler.java:99)
08-28 17:32:18.378: E/AndroidRuntime(6739): at android.os.Looper.loop(Looper.java:123)
08-28 17:32:18.378: E/AndroidRuntime(6739): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-28 17:32:18.378: E/AndroidRuntime(6739): at java.lang.reflect.Method.invokeNative(Native Method)
08-28 17:32:18.378: E/AndroidRuntime(6739): at java.lang.reflect.Method.invoke(Method.java:521)
08-28 17:32:18.378: E/AndroidRuntime(6739): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871)
08-28 17:32:18.378: E/AndroidRuntime(6739): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
08-28 17:32:18.378: E/AndroidRuntime(6739): at dalvik.system.NativeStart.main(Native Method)