0

Hi I am trying the android application connecting with web services from the following link

http://jatin4rise.wordpress.com/2010/10/03/part-2-calling-a-webservice-from-android-application/#comment-125

I am able to create xsdl file in web services This is the code in android

package com.example.androidwsdlfrontend;

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 AndroidWSDLFrontEnd extends Activity {
    private String METHOD_NAME = "sum"; // our webservice method name
    private String NAMESPACE = "http://calculator.backend.web.org";//&#8221"; // Here package name in webservice with reverse order.;

    private String SOAP_ACTION = NAMESPACE + METHOD_NAME; // NAMESPACE + method name

    private static final String URL = "http://10.0.2.2:8080/AndroidBackend/services/Calculate?wsdl";//&#8221"; // you

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_android_wsdlfront_end);

        TextView tv = (TextView) findViewById(R.id.txtAddition);
        try {
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            request.addProperty("i", 5);
            request.addProperty("j", 15);
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
            androidHttpTransport.call(SOAP_ACTION, envelope);
            Object result = envelope.getResponse();
            System.out.println("Result: " + result.toString());
            ((TextView) findViewById(R.id.txtAddition)).setText("Addition: "+ result.toString());
        } catch (Exception E) {
            E.printStackTrace();
            ((TextView) findViewById(R.id.txtAddition)).setText("Error: "+ E.getClass().getName() + ":" + E.getMessage());
        }
    }
}

In the above code when I compile I am getting the error at

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

But I am not knowing how to resolve it. Please help me. I have mentioned my ipaddress at that particular position.

Baradwaj Aryasomayajula
  • 1,184
  • 1
  • 16
  • 42
  • 3
    Stack trace matey? Post that logCat! – Skynet Dec 27 '13 at 13:03
  • 12-27 08:08:30.663: E/AndroidRuntime(4344): FATAL EXCEPTION: main 12-27 08:08:30.663: E/AndroidRuntime(4344): java.lang.NoClassDefFoundError: org.ksoap2.serialization.SoapObject 12-27 08:08:30.663: E/AndroidRuntime(4344): at com.example.androidwsdlfrontend.AndroidWSDLFrontEnd.onCreate(AndroidWSDLFrontEnd.java:27) – Baradwaj Aryasomayajula Dec 27 '13 at 13:15
  • I think there is something wrong with the Library, kSoap. Have you imported it? This might come handy: http://stackoverflow.com/questions/10020740/how-do-i-import-jars-in-an-android-project – Skynet Dec 27 '13 at 13:17
  • Yeah I have downloaded once again and imported it.. If we don't import it it will show errors in the whole file right? – Baradwaj Aryasomayajula Dec 27 '13 at 13:23

1 Answers1

1
Job
  • 45
  • 7