OK there's probably a better way of doing it than this, but it works!
Code:
byte[][] my_chunks = LargeByteArrayToChunks(incomingArray, 10000);
foreach (byte[] chunk in my_chunks)
{
uploadObject.Size = chunk.Length;
uploadObject.MTOMPayload = chunk;
// call web service here and pass the uploadObject
}
And the LargeByteArrayToChunks function as follows...
Code:
private byte[][] LargeByteArrayToChunks(byte[] original_data, int max_chunk_size)
{
List<byte> buffer = new List<byte>(original_data);
List<byte[]> result = new List<byte[]>();
while (buffer.Count > max_chunk_size)
{
result.Add(buffer.GetRange(0, max_chunk_size).ToArray());
buffer.RemoveRange(0, max_chunk_size);
}
if (buffer.Count > 0) // remember to check if there is any residual
result.Add(buffer.ToArray());
return result.ToArray();
}