android ksoap2 stackoverflow错误

时间:2014-07-09 12:12:48

标签: android ksoap2

我只是尝试使用我创建的Web服务执行简单的Web服务数据提取。当我去运行该程序时,它崩溃了我。我已经搜索过这个问题并没有运气,有人可以帮帮我吗?

public void getMessage() {
    private final String NAMESPACE = "http://tempuri.org/";
    private final String URL = "http://10.19.9.148/RFID/Service1.asmx";
    private final String SOAP_ACTION = "http://tempuri.org/HelloWorld";
    private final String METHOD_NAME = "HelloWorld";
    private String TAG = "SOAP";

    private static String message;


    //Create request
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    //Property which holds input parameters
    PropertyInfo messagePI = new PropertyInfo();
    //Set Name
    messagePI.setName("Practice");
    //Set Value
    messagePI.setValue(messagePI);
    //Set dataType
    messagePI.setType(String.class);
    //Add the property to request object
    request.addProperty(messagePI);
    //Create envelope
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER11);
    envelope.dotNet = true;
    //Set output SOAP object
    envelope.setOutputSoapObject(request);
    //Create HTTP call object
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

    try {
        //Invoke web service
        androidHttpTransport.call(SOAP_ACTION, envelope);
        //Get the response
        SoapObject result = (SoapObject) envelope.bodyIn;
        //Assign it to fahren static variable
       // message = response.toString();

        if(result !=null){
            tv.setText(result.getProperty(0).toString());
        }


        //tv.setText("" + results);

    } catch (Exception e) {
        tv.setText(e.getMessage());
        //e.printStackTrace();
    }
}

当我在调试模式中单步执行时,它会在行androidHttpTransport.call(SOAP_ACTION, envelope);处出错,然后在我的日志中显示

07-09 07:32:11.309: E/AndroidRuntime(8343): FATAL EXCEPTION: main
07-09 07:32:11.309: E/AndroidRuntime(8343): java.lang.StackOverflowError
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.String._getChars(String.java:1040)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:155)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:219)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serialization.PropertyInfo.toString(PropertyInfo.java:215)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:203)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serialization.PropertyInfo.toString(PropertyInfo.java:219)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:203)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serialization.PropertyInfo.toString(PropertyInfo.java:219)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:203)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serialization.PropertyInfo.toString(PropertyInfo.java:219)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:203)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serialization.PropertyInfo.toString(PropertyInfo.java:219)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:203)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serialization.PropertyInfo.toString(PropertyInfo.java:219)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:203)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serialization.PropertyInfo.toString(PropertyInfo.java:219)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:203)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serialization.PropertyInfo.toString(PropertyInfo.java:219)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:203)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serialization.PropertyInfo.toString(PropertyInfo.java:219)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:203)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serialization.PropertyInfo.toString(PropertyInfo.java:219)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:203)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serialization.PropertyInfo.toString(PropertyInfo.java:219)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:203)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serialization.PropertyInfo.toString(PropertyInfo.java:219)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:203)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serialization.PropertyInfo.toString(PropertyInfo.java:219)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:203)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serialization.PropertyInfo.toString(PropertyInfo.java:219)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:203)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serialization.PropertyInfo.toString(PropertyInfo.java:219)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:203)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serialization.PropertyInfo.toString(PropertyInfo.java:219)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:203)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serialization.PropertyInfo.toString(PropertyInfo.java:219)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:203)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serialization.PropertyInfo.toString(PropertyInfo.java:219)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:203)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serialization.PropertyInfo.toString(PropertyInfo.java:219)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:203)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serialization.PropertyInfo.toString(PropertyInfo.java:219)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:203)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serialization.PropertyInfo.toString(PropertyInfo.java:219)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:203)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serialization.PropertyInfo.toString(PropertyInfo.java:219)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:203)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serialization.PropertyInfo.toString(PropertyInfo.java:219)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:203)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serialization.PropertyInfo.toString(PropertyInfo.java:219)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:203)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serialization.PropertyInfo.toString(PropertyInfo.java:219)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:203)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serialization.PropertyInfo.toString(PropertyInfo.java:219)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:203)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serialization.PropertyInfo.toString(PropertyInfo.java:219)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:203)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serialization.PropertyInfo.toString(PropertyInfo.java:219)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:203)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serialization.PropertyInfo.toString(PropertyInfo.java:219)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at java.lang.StringBuffer.append(StringBuffer.java:203)
07-09 07:32:11.309: E/AndroidRuntime(8343):     at org.ksoap2.serializatio

1 个答案:

答案 0 :(得分:0)

import java.net.SocketException;

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 android.R.string;
import android.content.Context;
import android.util.Log;

public class Services {
    private static String SOAP_ACTION;
    private static String METHOD_NAME;
    private static String NAMESPACE = "http://tempuri.org/";

    private static String URL = "xyz";

    private static Context mContext;

    // Register User
    public static String Register(Context context, String StudentCode,
            ) {

        SOAP_ACTION = "http://tempuri.org/Register";
        METHOD_NAME = "Register";

        mContext = context;
        String result = null;

        // Ack
        Log.e("method", "Register");

        try {
            SoapPrimitive responses = null;
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

            // Property PassCode
            PropertyInfo piStudentCode = new PropertyInfo();
            piStudentCode.setName("sPassCode");
            piStudentCode.setValue(StudentCode);
            piStudentCode.setType(string.class);
            request.addProperty(piStudentCode);



            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);
            HttpTransportSE andHttp = new HttpTransportSE(URL);

            try {
                andHttp.call(SOAP_ACTION, envelope);
                responses = (SoapPrimitive) envelope.getResponse();

            } catch (SocketException ex) {
                Log.e("Register SE ex", ex.toString());
                ex.printStackTrace();
            } catch (Exception e) {
                Log.e("Register ex", e.toString());
                e.printStackTrace();
            }

            result = responses.toString();
        } catch (Exception e) {
            e.printStackTrace(System.err);
            Log.e("Register main ex", e.toString());
        }

        return result;
    }

我使用的方式,希望它也可以帮到你