Passing array list per parameter

1

I have the following problem:

I need to pass some files (xmls and pdf) from my winforms application to a webservice.

The problem is that you can not pass via parameters to a WS data type such as List < >.

In this case, I'm going to make it past the array containing the bytes of the file, so I can render it on the server inside WS.

I'm having trouble sending and receiving this list through a list.

// Cada arquivo eu insiro em um List<byte[]>, exemplo:
listaDeBytes.Add(File.ReadAllBytes(arrayAnexos[x]));

In this case, I have in my list 3 records with their respective bytes inside. To make this list an array, do the following:

// Transformando a List<byte[]> em uma array de byte:
byte[] listaEmByte = listaDeBytes.SelectMany(a => a).ToArray();

At this point, he inserted the 3 records with their bytes in this array, but it seems to have put everything together. The problem is how to interpret this list that I receive in my WS. How to turn it back into a list of bytes so I can read it.

I tried to convert it to a byte [] [], but it is not possible to convert the list to byte [] [] through SelectMany.

Any help is welcome. Thank you.

    
asked by anonymous 26.09.2017 / 15:21

1 answer

0

The syntax for converting your byte array list to a two-byte array of bytes should be this:

byte[][] listaEmByte = listaDeBytes.SelectMany(a => new byte[][]{a}).ToArray();

Or if you want to remove redundant code, we can remove the part that creates the array explicitly.

byte[][] listaEmByte = listaDeBytes.SelectMany(a => new[] { a }).ToArray();
    
26.09.2017 / 15:41