0

我正在使用 .net Web 服务 ksoap,我得到二进制字符串作为响应。我想将此字符串转换为图像并希望在 ImageView 中显示此图像。我正在从服务器获取图像/文档/pdf。

我的代码:

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());

我应该使用什么来显示任何类型的文件 image/doc/pdf。如何将此二进制字符串转换为正确的格式以及如何下载它???我感到很困惑。

//位图是个好主意吗?

这段代码在日志中以二进制形式给我响应。我想将其转换为 Image/doc 文件/pdf 文件并希望将其下载到本地 sd 卡中。

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>

请建议谢谢

4

1 回答 1

1

理想情况下,您可以让 API 给您一个指向文档/图像的链接,然后您可以下载它。

在响应中包含二进制数据不仅会使您的代码复杂,而且还会使您解析。

更新: 将二进制字符串转换为文件,就像读取数据并将其写入文件一样简单。

我建议,不要在我的回复的第一部分使用这种方法。

于 2013-03-15T10:44:21.110 回答