FATAL Exception主要android(通过Soap访问Web服务)

时间:2013-03-17 20:25:03

标签: android exception ksoap

我是Android开发的新手,我试图通过UltiDiv访问我本地托管的网络服务,当我运行应用程序时它给了我胎儿异常,我在android清单中添加了INTERNET和NETWORK_STATE权限,但它仍然是相同的。 Web服务名称为connecto,方法名称为DbRead,并采用字符串电话

    // here is the code 
    package finalProject.test.webService;
    import org.ksoap2.SoapEnvelope;
    import org.ksoap2.serialization.SoapObject;
    import org.ksoap2.serialization.SoapPrimitive;
    import org.ksoap2.serialization.SoapSerializationEnvelope;
    import org.ksoap2.transport.HttpTransportSE;
    import android.app.*;
    import android.util.Log;
    import android.widget.TextView;
    import android.os.Bundle;
    public class FinalWebServiceDemoActivity extends Activity {
    // some parameters regarding your web-service to be invoked
private static final String SOAP_ACTION = "http://tempuri.org/connecto";
    private static final String METHOD_NAME = "DbRead";
    private static final String NAMESPACE = "http://tempuri.org/";
    private static final String URL = "http://192.168.1.8:8080/connecto.asmx";

    TextView tv;

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    tv=(TextView)findViewById(R.id.text1);
    call();
    }

    public void call()
    {
    try {
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        request.addProperty("phone","1234");

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

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        androidHttpTransport.call(SOAP_ACTION, envelope);

        SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
        String strRes = result.toString();

        tv.setText(strRes);
        } catch (Exception e) {
        tv.setText("Exception...");
        Log.i("exception", e.toString());
        StackTraceElement elements[] = e.getStackTrace();
        for (int i = 0, n = elements.length; i < n; i++) {      
            Log.i("File", elements[i].getFileName());
            Log.i("Line", String.valueOf(elements[i].getLineNumber()));
            Log.i("Method", elements[i].getMethodName());
        }
        }
        }
         }  

1 个答案:

答案 0 :(得分:1)

用2.4代替Ksoap 2.6.0解决: - )