1

I am trying to serialize an object and send it over the web. I can serialize and immediately deserialize the object just fine. However, when I try to send the bytes over HTTP using this on the server side:

byte[] b = ObjectToByteArray(anObject);
SimpleWorkerRequest.SendResponseFromMemory(b, b.Length);

and then use on the client side:

WebClient client = new WebClient();
byte[] result = client.DownloadData(url);

the result bytes do not match the byte b that was sent. I have tried changing the encoding used, but it only changes the bytes around, they never match. I did see that WebClient has an encoding field, but that is only for DownloadString. What sort of encoding is used for client.DownloadData? How can I ensure the bytes stay the same? If there is an alternative to SimpleWorkerRequest that lets me send text, that would be awesome too..

Edit: If I make an ASP.NET project and use

Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition",
                                 "attachment; filename=whatever.bin");

It works! I tried to go back to the SimpleWorkerRequest and add:

swr.SendKnownResponseHeader(System.Web.HttpWorkerRequest.HeaderContentType, "application/octet-stream");

But I am not sure about the other part.. if I browse to the page, it displays as text, not a download

RichardJohnn
  • 654
  • 9
  • 24

0 Answers0