You need to transfer the .apk file using webservice

I converted my apk file to byte array and sent it using webservice as follows

[WebMethod] public byte[] GetApkFile(string deviceID) { try { string path = ServiceHelper.GetTempFilePath(); string fileName = path + "\\VersionUpdate.apk"; FileStream fileStream = File.OpenRead(fileName); return ConvertStreamToByteBuffer(fileStream); } catch (Exception ex) { throw ex; } } public byte[] ConvertStreamToByteBuffer(System.IO.Stream theStream) { int b1; System.IO.MemoryStream tempStream = new System.IO.MemoryStream(); while ((b1 = theStream.ReadByte()) != -1) { tempStream.WriteByte(((byte)b1)); } return tempStream.ToArray(); } 

I used a web service using the ksoap protocol in an android application as array bytes as below

 public void DownloadApkFile(String serverIPAddress, String deviceId) { String SOAP_ACTION = "http://VisionEPODWebService/GetApkFile"; String OPERATION_NAME = "GetApkFile"; String WSDL_TARGET_NAMESPACE = "http://VisionEPODWebService/"; String SOAP_ADDRESS = ""; SOAP_ADDRESS = "http://" + serverIPAddress + "/VisionEPODWebService/SystemData.asmx"; SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, OPERATION_NAME); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER10); new MarshalBase64().register(envelope); envelope.encodingStyle = SoapEnvelope.ENC; request.addProperty("deviceID", deviceId); envelope.dotNet = true; envelope.setOutputSoapObject(request); HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS); try { httpTransport.call(SOAP_ACTION, envelope); Object response = envelope.getResponse(); byte[] b=response.toString().getBytes(); String fileName = "/sdcard/" + "VersionUpdate" + ".apk"; FileOutputStream fileOuputStream = new FileOutputStream(fileName); fileOuputStream.write(b); fileOuputStream.close(); } catch (Exception exception) { exception.toString(); } 

The problem is that I am not getting the exact apk file after converting the byte array [] back to the file.

Someone please look at the code and please tell me if there is an error in this.

I need to return the converted byte [] apk file back to the .apk file in the SD card for installation.

+6
source share
1 answer

response.toString() most likely not a string representation of your APK.

Try the following:

 SoapObject result = (SoapObject)envelope.bodyIn; byte[] b=result.toString().getBytes(); 
+1
source

Source: https://habr.com/ru/post/901501/


All Articles