Android应用程序中的XMLPullParserException

时间:2013-07-09 03:49:29

标签: android web-services ksoap2

我正在尝试使用KSOAP2库从Android应用程序调用本地Web服务ASP.net(C#) 但是当我从Web服务调用WebMethod时,我得到了以下异常:

enter image description here

这里是主要的活动代码:

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.text.AlteredCharSequence;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;;

public class MainActivity extends Activity { 
    public static String result;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button b1 = (Button) findViewById(R.id.button1);
        b1.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                TextView TT = (TextView) findViewById(R.id.txt);
                try
                {
                    result = "START";
                    Caller CC = new Caller();
                    CC.join();
                    CC.start();
                    while (result == "START")
                    {
                        try
                        {
                            Thread.sleep(10);
                        }
                        catch (Exception s){}
                    }
                    TT.setText(result);
                }
                catch (Exception e)
                {
                    TT.setText(e.toString());
                }
            }
        });
    }
}

这是来电者班:

public class Caller extends Thread {
    CallSoap SS;
    public void run (){
        try
        {
            SS = new CallSoap();
            MainActivity.result = SS.call();
        }
        catch (Exception ex)
        {
            MainActivity.result = ex.toString();
        }
    }
}

最后是CallSoap类:

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.HttpTransportSE;
import org.ksoap2.serialization.PropertyInfo;

public class CallSoap {
    public final String SOAP_ACTION = "http://tempuri.org/Add";
    public  final String OPERATION_NAME = "Add"; 
    public  final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
    public  final String SOAP_ADDRESS = "http://10.0.2.2:9377/Service.asmx";
    public CallSoap () {

    }
    public String call ()
    {
        SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
        request.addProperty("a",100);
        request.addProperty("b",200);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);
        HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
        SoapPrimitive response=null;
        try
        {
           httpTransport.call(SOAP_ACTION, envelope);
           response = (SoapPrimitive) envelope.getResponse();
        }
        catch (Exception exception)
        {
           return exception.toString(); 
        }
       return response.toString();
    }
}

来自Web服务的调用Web方法非常简单,它需要两个整数并返回它们的总和,方法名称为Add,第一个参数是a,第二个一个是b

任何人都可以帮助这个例外吗? :)

0 个答案:

没有答案