How do I pass a byte array from JavaScript to an ActiveX control.
My JavaScript will call WCF server (method) and that method will return a byte array. After that I need to pass this byte array to the ActiveX control.
Could anybody provide me a solution fo开发者_运维技巧r this?
Depending on what binding your WCF service uses (and as you are calling it from javascript I assume webHttpBinding
) it is quite possible that the returned byte array will be returned as a base 64 encoded string. So you might need to modify the ActiveX component to accept a base 64 encoded string as parameter instead of a byte array.
From javascript you will have a form of base64_encode string. ActiveX component should have a function to convert string to byte array like this
byte[] string2byte(string s)
{
byte[] b = new byte[s.Length / 2];
for (int i = 0; i < s.Length; i += 2) { b[i / 2] = Convert.ToByte(s.Substring(i, 2), 16); }
return b;
}
I solved the problem by returning base64string rather than a byte array from the WCF Service.
So that i can simply convert the Base64 string usning Convert.FromBase64String() method to byte arrary.
精彩评论