Flashbuilder 4.5、Actionscript 3、WSDL:对收到的字节数组/字符串进行编码时出现奇怪的结果
我正在使用 C# Soap Web 服务,并使用它尝试将图像发送到 Actionscript(我正在使用 Adobe Air)。我可以通过两种方式返回这个二进制数据,在 C# 端返回一个 String,或者返回一个 byte[]。两者给出相同的结果(除了字符串周围有“”)。当我在 Flash Builder 中测试操作时,我也得到了完全相同的字符串。
然而,当我尝试将此字符串编码为 Binary64Data(这就是 xml 描述中的正式内容)时,我得到了一个奇怪的结果。两个字符串应该是相同的,但是编码后的字符串的后半部分不同。最终我想从中得到一个 ByteArray,我可以用它来创建我的图像。这与 String 版本完美配合,但另一个版本返回半毁(但可识别)的图像。
我的问题可能是什么?这是我的代码,当使用字符串时:
// This works:
var data:String = getBinaryString(); // Returns the result from webservice call token.lastResult
// Remove the two quotes
data = data.substr(1);
data = data.substr(0, data.length-1);
// Decode the base64 string
var dec : Base64Decoder = new Base64Decoder();
dec.decode(data);
imgByteArray = dec.toByteArray();
// Load the image:
loader = new Loader();
loader.loadBytes(bytes);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaderCompleteHandler);
// in the event handler:
var bmp:Bitmap = Bitmap(loader.content);
// Some misc stuff, but eventually an image shows, the correct image
但是当我尝试应该返回 ByteArray 的 webservice 方法时:
var data = getBinaryData(); // returns the result from webservice again
var enc : Base64Encoder = new Base64Encoder ();
enc.insertNewLines = false;
enc.encode(data);
var dataString:String = enc.flush(); // also tried toString(), same result
// This dataString should be eactly the same as the above datastring,
// but for some reason, the second half of the string is entirely different,
// while the first half is exactly the same
我做错了什么吗?最好我想跳过整个编码/解码,只使用 ByteArray,Web 服务调用应该首先返回,但是当我尝试将其转换为这样时:
var data:ByteArray = getBinaryData() as ByteArray;
数据变为空。同样的数据可以用上面的序列进行变换,所以数据不为空。
我该如何解决我的问题?再次请注意,在 Flash Builder 中,使用测试操作工具,两个 String 作为 ByteArray Webservice 调用返回相同的值,只是在 Actionscript 3 中我的值有所不同。
I am using a C# Soap Webservice, and using this I am trying to sent an image to Actionscript (I am using Adobe Air). I can return this binary data in two ways, return a String on the C# side, or a byte[]. Both give the same result (except that string has “” around it). When I test the operation in Flash Builder, I also get the exact same String.
However, when I try to encode this string into Binary64Data, which is what it officially is in the xml description, I get an odd result. Both Strings should be the same, but the later half of the encoded String is different. Eventually I want to get a ByteArray out of it, which I can use to create my image. This works perfectly with the String version, but the other version returns a half-ruined (but recognizable) image.
What could my problem be? Here is my code, when using a string:
// This works:
var data:String = getBinaryString(); // Returns the result from webservice call token.lastResult
// Remove the two quotes
data = data.substr(1);
data = data.substr(0, data.length-1);
// Decode the base64 string
var dec : Base64Decoder = new Base64Decoder();
dec.decode(data);
imgByteArray = dec.toByteArray();
// Load the image:
loader = new Loader();
loader.loadBytes(bytes);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaderCompleteHandler);
// in the event handler:
var bmp:Bitmap = Bitmap(loader.content);
// Some misc stuff, but eventually an image shows, the correct image
But when I try the webservice method that should return a ByteArray:
var data = getBinaryData(); // returns the result from webservice again
var enc : Base64Encoder = new Base64Encoder ();
enc.insertNewLines = false;
enc.encode(data);
var dataString:String = enc.flush(); // also tried toString(), same result
// This dataString should be eactly the same as the above datastring,
// but for some reason, the second half of the string is entirely different,
// while the first half is exactly the same
Is there something I am doing wrong? Preferably I would want to skip the entire encoding/decoding, and just use the ByteArray the webservice call is supposed to return in the first place, but when I try to cast it as such:
var data:ByteArray = getBinaryData() as ByteArray;
Data becomes null. This same data can be transformed with the above sequence, so the data is not empty.
How can I solve my problem? Again, please note that in Flash Builder, using the test operation facilities, both the String as the ByteArray webservice calls return the same value, it is only in the Actionscript 3 that my values diverge.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你想要将一个对象转换为ByteArray,你需要调用ByteArray方法convertObject()。
试试这个:
If what you want to do is convert an object to a ByteArray, you need to call the ByteArray method convertObject().
Try this: