如何从 Android 中的 Web 服务检索二进制数据?

发布于 2024-11-15 15:56:22 字数 592 浏览 2 评论 0原文

   SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);          
   Log.d("WebService", "2");
   SoapSerializationEnvelope envelope = 
          new SoapSerializationEnvelope(SoapEnvelope.VER11);
   envelope.dotNet = true;
   envelope.setOutputSoapObject(request);
   HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
   androidHttpTransport.call(SOAP_ACTION, envelope);                    
   SoapPrimitive result = (SoapPrimitive)envelope.getResponse();

这是我调用发送 byte[] 数组的 .NET Web 服务的代码。如何从结果变量中获取 byte[] 数组,或者是否有另一种方法来检索 byte[] 数组?

   SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);          
   Log.d("WebService", "2");
   SoapSerializationEnvelope envelope = 
          new SoapSerializationEnvelope(SoapEnvelope.VER11);
   envelope.dotNet = true;
   envelope.setOutputSoapObject(request);
   HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
   androidHttpTransport.call(SOAP_ACTION, envelope);                    
   SoapPrimitive result = (SoapPrimitive)envelope.getResponse();

This is the code where I call a .NET web service which sends a byte[] array. How can I get the byte[] array from the result variable or is there another approach to retrieve byte[] array?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风筝在阴天搁浅。 2024-11-22 15:56:22

假设所提供的代码使用 kSoap2。如果您想访问检索到的数据,请忘记 envelope.getResponse() 返回的响应对象。

您要查找的数据可以通过以下方式检索。

SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
if (resultsRequestSOAP != null) {
  Object o = resultsRequestSOAP.getProperty("name of the byte-array parameter");
  // ...
}

返回的对象 o 通常是 SoapPrimitive 类型,也可能是 Vector

如果它是 SoapPrimitive,使用它的 toString() 方法,您可以获得必须解析并转换为字节数组的字节数组的字符串表示形式。

如果它是一个向量,我认为将其转换为字节数组不会有问题。

Assuming that the presented code is using kSoap2. If you want to access the retrieved data forget about the response object returned by envelope.getResponse().

The data you are looking for can be retrieved via

SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
if (resultsRequestSOAP != null) {
  Object o = resultsRequestSOAP.getProperty("name of the byte-array parameter");
  // ...
}

The returned Object o is usually of the type SoapPrimitive or may be a Vector.

If it's a SoapPrimitive using it's toString() method you can get the String representation of the byte array that has to be parsed and converted to a byte array.

If it's a Vector I don't think that you will have problems converting it to a byte array.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文