2011-12-15 337 views
0

我需要一些幫助。Android客戶端Web服務

我正在開發一個應用程序android發送一個字節數組和一個字符串到Web服務。我的Android代碼的

配件:

private static final int SELECT_VIDEO = 100; 
private static final String NAMESPACE = "org.me.WebService"; 
private static final String URL = "http://192.168.1.4:8084/MyTubeWebService/MyTubeService?wsdl";  
private static final String SOAP_ACTION = "MyTubeService"; 
private static final String METHOD_NAME = "upArquivoVideo"; 

     //(...) 
     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);  
      SoapSerializationEnvelope envelope = 
       new SoapSerializationEnvelope(SoapEnvelope.VER11); 

      request.addProperty("arquivoVideo",video); 
      request.addProperty("descricao", "teste"); 
      envelope.setOutputSoapObject(request); 

      HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 

      try { 
       androidHttpTransport.call(SOAP_ACTION, envelope); 
       //androidHttpTransport.call(NAMESPACE+"/"+METHOD_NAME,envelope); 
       SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn; 
       text.setText("Received :" + resultsRequestSOAP.toString()); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 

和Web服務代碼:

@WebService(serviceName = "MyTubeService") 
public class MyTubeService { 

/** 
* Operação de serviço web 
*/ 
@WebMethod(operationName = "upArquivoVideo") 
@Oneway 
public void upArquivoVideo(@WebParam(name = "arquivoVideo") byte[] arquivoVideo, @WebParam(name = "descricao") String descricao) { 

    if (arquivoVideo.length > 0){ 
     System.out.println("OK!"); 
    }else{ 
     System.out.println("Erro"); 
    } 

    System.out.println("desricao = " + descricao); 

} 

日誌貓一次調度異常的Socket超時......在我的最後一次測試調度RuntimeException:無法序列化

我在做什麼錯?它是在Android端?或者在Web服務端?

回答

0

首先,您需要提高您的接受率才能獲得答案。

我看到你有問題使用kso​​ap向你的web服務發送一個字符串和一個字節數組。

這裏是一個字符串發送到Web服務的一種方式:

private String doLogin(String user_id, String password) 
    { 
    SoapPrimitive resultstring = null; 
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
    request.addProperty("user", user_id); 
    request.addProperty("password", password); 
    SoapSerializationEnvelope soapenvelope = new SoapSerializationEnvelope(
        SoapEnvelope.VER11); 
    soapenvelope.dotNet = true; //only if it is .net webservice              
    soapenvelope.setOutputSoapObject(request); 

    AndroidHttpTransport httptransport = new AndroidHttpTransport(URL); 
    httptransport.debug = true; 

    try { 
      httptransport.call(SOAP_ACTION, soapenvelope); 
      resultstring = (SoapPrimitive) soapenvelope.getResponse(); 
    //change above line depending upon the response you get             


    } 
    catch (SocketException ex) { 
     Log.e("Error : " , "Error on soapPrimitiveData() " + ex.getMessage()); 
     ex.printStackTrace(); 
    } catch (Exception e) { 
     Log.e("Error : " , "Error on soapPrimitiveData() " + e.getMessage()); 
     e.printStackTrace(); 
    } 
    return resultstring+""; 

    } 

同樣,我希望你可以編寫代碼來發送一個字節數組。有許多教程和代碼片段可以幫助您。

希望這有助於

乾杯