1

I am using .net web services ksoap and I am getting Binary string in response. I want to convert this string into image and want to display this image in ImageView. I am getting images/doc/pdf's from server.

My code:

SoapObject DocumentRequest = new SoapObject(NAMESPACE, GET_DOCUMENT_METHOD);

        DocumentRequest.addProperty("DocumentID", ID);
        Log.i("DocumentID", ID);

        SoapSerializationEnvelope Envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        Envelope.dotNet = true;
        Envelope.setOutputSoapObject(DocumentRequest);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        androidHttpTransport.debug = true;

        androidHttpTransport.call(SOAP_ACTION_GETDOCUMENT, Envelope);

        SoapPrimitive DocumentResponse = (SoapPrimitive)Envelope.getResponse();
        Log.i("DocumentResponse", DocumentResponse.toString());

What should I use to display any type of file image/doc/pdf. How to convert this binary string into correct format and how to download it??? I am so confused.

//Is bitmap is good Idea?

this code is giving me response in binary in log. I want to convert this in Image/doc file/pdf file and want to download it in local sd card.

POST /**********Mobile/**********.asmx HTTP/1.1
Host: 192.168.1.5
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/GetDocument"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     
xmlns:xsd="http://www.w3.org/2001/XMLSchema"    
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
 <GetDocument xmlns="http://tempuri.org/">
   <DocumentID>string</DocumentID>
 </GetDocument>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
 <soap:Body>
   <GetDocumentResponse xmlns="http://tempuri.org/">
     <GetDocumentResult>string</GetDocumentResult>
   </GetDocumentResponse>
 </soap:Body>
</soap:Envelope>

Pleasesuggest thanks

1 Answer 1

1

Ideally, you could get the API give you back a link to the doc/image, and then later, you can download it.

Having binary data in a response, not only makes your code complex, but also, you parsing.

Update: Converting a binary string into a file, is as easy as reading the data, and writing it into a file.

I suggested, not to use this approach in the first part of my response.

Sign up to request clarification or add additional context in comments.

5 Comments

Sorry I don't understand. Can you please let me know how to convert binary string into image in android?
ok, So what to do? I also have base64binary String, is it good?
Oh. You didn't mention that. For that, decode the binary string using Base64, and write the resulting string to a file. You are done.
ok, So you mean base64 approach is better then binary String? Right?
Can you please write a code sample for me, i got your point but I am confused in writing code. how to create a file?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.