2013-12-10 34 views
0

我在執行HttpTransportSE中的調用方法時出現錯誤:Java.lang.RuntimeException: Cannot serialize : -119將字節數組發送到webservice時出現Java序列化錯誤

我曾嘗試直接將兩者對象:

public String UploadPhotoCall(byte[] imageContent) 
SoapObject request = new SoapObject(_wsdlTargetNamespace, _operation); 
request.addProperty("imageContent", imageContent); 
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
envelope.dotNet = true; 
envelope.setOutputSoapObject(request); 
HttpTransportSE httpTransport = new HttpTransportSE(_soapAddressLocation); 
Object response = null; 
try{ 
httpTransport.call(_action, envelope); 
response = envelope.getResponse(); 
} 
catch(IOException ex){ 
response = ex.toString(); 
} 
catch(Exception ex){ 
response = ex.toString(); 
} 

和閱讀話題Pass Array using Web services in Ksoap2
後,我嘗試這樣做:

SoapObject request = new SoapObject(_wsdlTargetNamespace, _operation); 
PropertyInfo propertyImage = new PropertyInfo(); 

SoapObject soapImage = ByteArrayTransform(imageContent); 
propertyImage.setValue(soapImage); 
propertyImage.setType(soapImage.getClass()); 
propertyImage.setName("imageContent"); 
request.addProperty(propertyImage); 


public SoapObject ByteArrayTransform(byte[] image){ 
SoapObject soapImage = new SoapObject(_wsdlTargetNamespace, _operation); 
Log.i(_TAG, "byte array transform begins"); 
for (int i =0; i < image.length; i++){ 
    soapImage.addProperty(Integer.toString(i), image[i]); 
} 
return soapImage; 
} 

但它仍然沒有幫助。任何人都可以告訴我,如何以正確的方式做到這一點?

回答

0

好的,最後我設法解決了這個問題。 添加字節數組要求工作在兩種方法,他們只是缺少一個聲明SoapObject已經被添加到信封后:

new MarshalBase64().register(envelope); 

我希望有人發現它是有用的。

相關問題