|
Alright, I'll admit, after days of looking at this code I'm a bit at my wits end. At a high level it's a project that uses a client server architecture to deliver a stream object via wcf for large data transfers. The blog and project I've utilized can be found here:
http://blogs.msdn.com/b/webapps/archive/2012/09/06/custom-wcf-streaming.aspx[^]
My issue is this, the project works incredibly well with numeric values. But, if I add a few basic string values in, it'll process say 30 rows of data and then die, with the following message:
"The input stream is not a valid binary format. The starting contents (in bytes) are: 08-02-00-00-00-0A-00-00-00-0A-00-00-00-0A-00-00-00 ...
A summarized version of the code looks like this:
Server:
model.ID = i;
model.ParameterOne = i;
model.ParameterTwo = i;
model.ParameterThree = i;
model.AMP = stringCache[i - 1];
formatter.Serialize(memStream, model);
Client:
OrderModel m;
while (s.CanRead)
{
m = formatter.Deserialize(s) as OrderModel;
count++;
Console.Write(string.Format("order ID is {0}\r\n", m.ID));
}
I've run through multiple scenarios. I thought the wcf client was either timing out or being overloaded, but I can run it without wcf all in the same class and run into the same exact issue. I can also manually read and write to a memory stream not utilizing the server class and it works perfectly fine, so that proves it can't be encoding or issues with that data in general.
You can download the same project here (just three classes):
https://skydrive.live.com/redir.aspx?cid=8df0b4ca8325874a&page=self&resid=8DF0B4CA8325874A%21175&parid=8DF0B4CA8325874A%21110&authkey=%21&Bpub=SDX.SkyDrive&Bsrc=Share[^]
If you go to class DBRowStream and comment line 179, it works beautifully. If you uncomment it, it fails after 30 rows. My best guess is that the overriden read method of the class is killing the stream prematurely, but if that were the case, why would a few extra string values mean the difference between it working and not.
I apologize for the novel, and any suggestions or help would be so greatly appreciated!
Thanks so much,
Ryan
|
|
|
|
|
It's multithreaded; could it be that the memorystream is corrupted before the thread finishes?
|
|
|
|
|
You know I was wondering the same thing. Although it's odd that it makes it through exactly 30 rows every single time before it errors out. I was also thinking that because the author switches the memory stream from one of two other memory streams, that maybe the main memory stream is being overridden before a read is complete....
|
|
|
|
|
formatter.Deserialize(s) assumes that the entire object has been successfully written to the stream? For grins and giggle, try writing the entire stream to memory after 30 rows; I bet a dime to a dollar, all of your strings have not been completely written. At least that is what I would look into, don't know the answer myself as I completely avoid WCF like the plague.
|
|
|
|