views:

132

answers:

3

Hi

How do I pass a byte array from javascript to ActiveX control.

My javascript will call WCF server (method) and that method will return a byte array. After that I need to passs this byte array to the ActiveX control.

Could anybody provide me a solution for this.

A: 

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.

Darin Dimitrov
hi Darin,if i convert the base64 string to byte array using Convert.FromBase64String methodit is throwing an exceptioninvalid character in a base-64 string
kumar
A: 

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;
    }
dcool
A: 

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.

kumar