0

我無法解決這個問題,從Android客戶端連接到我的web服務時出現問題。在我的MainActivity類別的管線75中的程序崩潰:當連接到本地500內部服務器錯誤的web服務時,Android應用程序崩潰?

transporte.call(accionSoap, sobre); 

我認爲這個問題可能是與accionSoap東西,任何幫助將是非常apreciatted。

Web服務:

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) 

謝謝!

+0

'HTTP請求失敗,HTTP狀態:500'你的服務器告訴它崩潰。 – SLaks

+0

我的服務器很簡單,它只返回Hello +參數 – user2887592

+0

[Android連接IN LOCAL到webservice連接時崩潰]的可能重複(http://stackoverflow.com/questions/19428866/android-app-crashes-when-connecting -in-local-to-webservice) – Selvin

回答

0

嘗試刪除向前命名的命名空間=結束斜線「http://ws.webapp.org

+0

是的!現在我遇到了一個問題:SoapPrimitive resultado =(SoapPrimitive)sobre.getResponse(); java.lang.ClassCastException:org.ksoap2.serialization.SoapPrimitive不能轉換爲java.lang.String是否有幫助? – user2887592

+0

將其改爲Object,因爲您正在返回一個字符串 – ngunha02

+0

更改什麼?我很抱歉,我不明白,我很新...;) – user2887592

相關問題