在本地500内部服务器错误中连接到webservice时Android应用程序崩溃?

时间:2013-10-17 19:41:00

标签: java android web-services webservice-client exchangewebservices

我无法解决这个问题,从Android客户端连接到我的网络服务时遇到问题。在我的MainActivity类中,程序在第75行崩溃:

transporte.call(accionSoap, sobre); 

我认为问题可能与accionSoap有关,任何帮助都会非常令人沮丧。

网络服务:

package org.webapp.ws;

public class Hello {
 public String sayHello(String name) {
    return "Hello !!! " + name;
 }
}

MainActivity:

package com.example.ejemplosoap;

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.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity {

//Napespace definido en el servicio web
private final String namespace = "http://ws.webapp.org/";
//Fichero de definicion del servicio web
private final String url = "http://10.0.2.2:8080/WebServiceServer/services/Hello";
//namespace + metodo
private final String accionSoap = "http://ws.webapp.org/sayHello";
//Metodo que queremos ejecutar en el servicio web
private final String Metodo = "sayHello";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

public void onClickLogin(View view){

new ServiceCallTask().execute();
}

class ServiceCallTask extends AsyncTask<String, String, String>
{

@Override
protected String doInBackground(String... params) {
    try {

        System.out.println("1");
        // Modelo el request
        SoapObject request = new SoapObject(namespace, Metodo);
        //request.addProperty("name", "Juan!"); // Paso parametros al WS
        PropertyInfo primerParametro = new PropertyInfo ();
        System.out.println("2");
        primerParametro.setName("name");
        primerParametro.setValue("Juan");
        request.addProperty(primerParametro);
        System.out.println("3");
        // Modelo el Sobre
        SoapSerializationEnvelope sobre = new              SoapSerializationEnvelope(SoapEnvelope.VER11);
        //si esta hecho o no en puntoNet
        sobre.dotNet = false;
        sobre.setOutputSoapObject(request);
        System.out.println("4");

        // Modelo el transporte
        HttpTransportSE transporte = new HttpTransportSE(url);
        System.out.println("5");

        // Llamada
        transporte.call(accionSoap, sobre);
        System.out.println("6");

        // Resultado
        SoapPrimitive resultado = (SoapPrimitive) sobre.getResponse();
        String cadenaDevuelta =(String) sobre.getResponse();
        Log.i("Resultado", cadenaDevuelta);

    } catch (Exception e) {
        Log.e("MainActivity", "ERROR");
                e.printStackTrace();
    }
    return null;
}


}



}

logcat的:

10-17 15:46:23.466: W/Trace(747): Unexpected value from nativeGetEnabledTags: 0
10-17 15:46:23.486: W/Trace(747): Unexpected value from nativeGetEnabledTags: 0
10-17 15:46:23.497: W/Trace(747): Unexpected value from nativeGetEnabledTags: 0
10-17 15:46:23.497: W/Trace(747): Unexpected value from nativeGetEnabledTags: 0
10-17 15:46:23.497: W/Trace(747): Unexpected value from nativeGetEnabledTags: 0
10-17 15:46:23.506: W/Trace(747): Unexpected value from nativeGetEnabledTags: 0
10-17 15:46:23.506: W/Trace(747): Unexpected value from nativeGetEnabledTags: 0
10-17 15:46:23.506: W/Trace(747): Unexpected value from nativeGetEnabledTags: 0
10-17 15:46:23.526: W/Trace(747): Unexpected value from nativeGetEnabledTags: 0
10-17 15:46:23.526: W/Trace(747): Unexpected value from nativeGetEnabledTags: 0
10-17 15:46:23.556: I/System.out(747): 1
10-17 15:46:23.556: I/System.out(747): 2
10-17 15:46:23.566: I/System.out(747): 3
10-17 15:46:23.566: I/System.out(747): 4
10-17 15:46:23.566: I/System.out(747): 5
10-17 15:46:23.566: W/Trace(747): Unexpected value from nativeGetEnabledTags: 0
10-17 15:46:23.566: W/Trace(747): Unexpected value from nativeGetEnabledTags: 0
10-17 15:46:23.617: D/dalvikvm(747): GC_FOR_ALLOC freed 309K, 16% free 2601K/3068K, paused 35ms, total 35ms
10-17 15:46:23.617: W/Trace(747): Unexpected value from nativeGetEnabledTags: 0
10-17 15:46:23.626: W/Trace(747): Unexpected value from nativeGetEnabledTags: 0
10-17 15:46:23.845: E/MainActivity(747): ERROR
10-17 15:46:23.845: W/System.err(747): java.io.IOException: HTTP request failed, HTTP status: 500
10-17 15:46:23.865: W/System.err(747):  at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:195)
10-17 15:46:23.865: W/System.err(747):  at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:116)
10-17 15:46:23.875: W/System.err(747):  at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:111)
10-17 15:46:23.875: W/System.err(747):  at com.example.ejemplosoap.MainActivity$ServiceCallTask.doInBackground(MainActivity.java:75)
10-17 15:46:23.885: W/System.err(747):  at com.example.ejemplosoap.MainActivity$ServiceCallTask.doInBackground(MainActivity.java:1)
10-17 15:46:23.885: W/System.err(747):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
10-17 15:46:23.885: W/System.err(747):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
10-17 15:46:23.895: W/System.err(747):  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
10-17 15:46:23.905: W/System.err(747):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
10-17 15:46:23.905: W/System.err(747):  at     java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
10-17 15:46:23.905: W/System.err(747):  at java.lang.Thread.run(Thread.java:856)

谢谢!

1 个答案:

答案 0 :(得分:0)

尝试在namespace namespace =“http://ws.webapp.org

的末尾删除正斜杠