title: Send binary file in web service soap response
body: <p>I have response stream from a ftp web request that returns binary file.
  I wanted to get the binary data into byte[] and then encode that array and send it as web service response.</p>
  
  <pre><code>Stream responseStream = webResponse.GetResponseStream();
  byte[] byteToEncode= ReadFully(responseStream,1024);
  String str=Convert.ToBase64String(byteToEncode);
  </code></pre>
  
  <p>I used that function I found online to convert the stream into byte[]</p>
  
  <pre><code>/// &lt;summary&gt;
  /// Reads data from a stream until the end is reached. The
  /// data is returned as a byte array. An IOException is
  /// thrown if any of the underlying IO calls fail.
  /// &lt;/summary&gt;
  /// &lt;param name="stream"&gt;The stream to read data from&lt;/param&gt;
  /// &lt;param name="initialLength"&gt;The initial buffer length&lt;/param&gt;
  
  public static byte[] ReadFully (Stream stream, int initialLength)
  {
      // If we've been passed an unhelpful initial length, just  use 32K.
      if (initialLength &lt; 1)
      {
          initialLength = 32768;
      }
  
      byte[] buffer = new byte[initialLength];
      int read=0;
  
    int chunk;
      while ( (chunk = stream.Read(buffer, read, buffer.Length-read)) &gt; 0)
      {
          read += chunk;
  
          // If we've reached the end of our buffer, check to see if there's
          // any more information
  
          if (read == buffer.Length)
          {
              int nextByte = stream.ReadByte();
  
              // End of stream? If so, we're done
  
              if (nextByte==-1)
              {
                  return buffer;
              }
  
              // Nope. Resize the buffer, put in the byte we've just
              // read, and continue
              byte[] newBuffer = new byte[buffer.Length*2];
  
              Array.Copy(buffer, newBuffer, buffer.Length);
              newBuffer[read]=(byte)nextByte;
              buffer = newBuffer;
              read++;
          }
      }
      // Buffer is now too big. Shrink it.
  
      byte[] ret = new byte[read];
      Array.Copy(buffer, ret, read);
      return ret;
  } 
  </code></pre>
  
  <p>But I got an exception says:</p>
  
  <pre><code>This stream does not support seek operations.
  </code></pre>
  
  <p>I would appreciate any help.</p>
  
  <p>Thanks,
  Sarah </p>