使用android错误调用Web服务时出错

时间:2014-10-19 16:52:11

标签: java android asp.net web-services

大家好,我的android应用程序调用ASP Web服务时遇到问题 每次我使用该应用程序时都会收到此消息

不幸的是 “my-app-Name”已经停止。

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;

/**
 * @author AndroidExample DotNetWebService Class
 * 
 */
public class WebserviceCall {

    /**
     * Variable Decleration................
     * 
     */
    String namespace = "http://192.168.11.140/";
    private String url = "http://192.168.11.140/theService/Service.asmx";

    String SOAP_ACTION;
    SoapObject request = null, objMessages = null;
    SoapSerializationEnvelope envelope;
    AndroidHttpTransport androidHttpTransport;

    WebserviceCall() {
    }


    /**
     * Set Envelope
     */
    protected void SetEnvelope() {

        try {

            // Creating SOAP envelope           
            envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

            //You can comment that line if your web service is not .NET one.
            envelope.dotNet = true;

            envelope.setOutputSoapObject(request);
            androidHttpTransport = new AndroidHttpTransport(url);
            androidHttpTransport.debug = true;

        } catch (Exception e) {
            System.out.println("Soap Exception---->>>" + e.toString());    
        }
    }

    // MethodName variable is define for which webservice function  will call
    public String getConvertedWeight(String MethodName, String Pro1,
            String Pro2) 
      {

        try {
            SOAP_ACTION = namespace + MethodName;

            //Adding values to request object
            request = new SoapObject(namespace, MethodName);



            request.addProperty("Pro1", Pro1);
            request.addProperty("Pro2", Pro2);

            SetEnvelope();

            try {

                //SOAP calling webservice
                androidHttpTransport.call(SOAP_ACTION, envelope);

                //Got Webservice response
                String result = envelope.getResponse().toString();

                return result;

            } catch (Exception e) {
                // TODO: handle exception
                return e.toString();
            }
        } catch (Exception e) {
            // TODO: handle exception
            return e.toString();
        }

    }


    /************************************/
}

我alredy在“AndroidManifest.xml”文件中添加了这一行

<uses-permission android:name="android.permission.INTERNET" />

请任何人都可以帮助我

修改

10-20 07:31:41.463: E/AndroidRuntime(531): FATAL EXCEPTION: main
10-20 07:31:41.463: E/AndroidRuntime(531): java.lang.NoClassDefFoundError: org.ksoap2.serialization.SoapObject
10-20 07:31:41.463: E/AndroidRuntime(531):  at com.service.newgetwebservice.WebserviceCall.getConvertedWeight(WebserviceCall.java:61)
10-20 07:31:41.463: E/AndroidRuntime(531):  at com.service.newgetwebservice.MainActivity$1.onClick(MainActivity.java:37)
10-20 07:31:41.463: E/AndroidRuntime(531):  at android.view.View.performClick(View.java:3511)
10-20 07:31:41.463: E/AndroidRuntime(531):  at android.view.View$PerformClick.run(View.java:14105)
10-20 07:31:41.463: E/AndroidRuntime(531):  at android.os.Handler.handleCallback(Handler.java:605)
10-20 07:31:41.463: E/AndroidRuntime(531):  at android.os.Handler.dispatchMessage(Handler.java:92)
10-20 07:31:41.463: E/AndroidRuntime(531):  at android.os.Looper.loop(Looper.java:137)
10-20 07:31:41.463: E/AndroidRuntime(531):  at android.app.ActivityThread.main(ActivityThread.java:4424)
10-20 07:31:41.463: E/AndroidRuntime(531):  at java.lang.reflect.Method.invokeNative(Native Method)
10-20 07:31:41.463: E/AndroidRuntime(531):  at java.lang.reflect.Method.invoke(Method.java:511)
10-20 07:31:41.463: E/AndroidRuntime(531):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-20 07:31:41.463: E/AndroidRuntime(531):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-20 07:31:41.463: E/AndroidRuntime(531):  at dalvik.system.NativeStart.main(Native Method)

0 个答案:

没有答案