2011-03-19 193 views
0

作爲我項目的一部分,我需要將圖像上傳到服務器。在服務器部分,我有一個Web服務,它將接受字節數組並將其轉換爲圖像。在我的客戶端部分(Android + ksoap2)中,我使用Base64編碼將圖像轉換爲byte []數組。但是我無法將字節數組傳遞給Web服務。它顯示出一些序列化問題。 我如何使用kso​​ap2.Somebody請幫我的字節數組傳遞到Web服務.....將圖像上傳到服務器

+0

接受答案..如果得到解決方案 – MorningGlory 2011-11-21 12:05:27

回答

1

使用MarshalBase64

MarshalBase64 marshal = new MarshalBase64(); 
    ByteArrayOutputStream out = new ByteArrayOutputStream(); 
    bmp.compress(CompressFormat.PNG, 100, out); 
    byte[] raw = out.toByteArray(); 

    SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, 
     OPERATION_NAME); 
    request.addProperty("image", raw); 

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
     SoapEnvelope.VER11); 
    envelope.dotNet = true; 
    envelope.setOutputSoapObject(request); 
    marshal.register(envelope); 
    HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS); 

    try 

    { 

     httpTransport.call(SOAP_ACTION, envelope); 
     Object response = envelope.getResponse(); 
     } 

    catch (Exception exception) 

    { 
     exception.printStackTrace(); 

    } 

} 

參考Serialize byte array using ksoap android嘗試使用此代碼

序列化的字節數組

+0

我會試着用這個代碼.......謝謝.... – Jithin 2011-03-27 18:25:14