如何从 Android 中的 Web 服务检索二进制数据?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设所提供的代码使用 kSoap2。如果您想访问检索到的数据,请忘记
envelope.getResponse()
返回的响应对象。您要查找的数据可以通过以下方式检索。
返回的对象 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
The returned Object o is usually of the type
SoapPrimitive
or may be aVector
.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.