XML part deux

    Date: 09/26/05 (C Sharp)    Keywords: xml, web

    Sorry to post another XML question so soon, but I promise this one's fundamentally different enough from the last one to merit a new post...

    So I am creating an XML string in a class that gets bundled inside another XML string by another class before being sent to a WebService, where the reverse occurs (class members are populated by the XML string; a sort of deserialization, but not using the framework).

    Let me first say that it works. One of the XML nodes contains an image encoded with base64, which is how I've been testing whether the XML is successfully built, parsed, transmitted, etc. I have a small client application that builds the XML and tests it by deserializing the image and displaying it; the server receives the XML, deserializes the image, and saves the image to the filesystem, where I can verify that it saves properly, displays properly, and all that jazz. So everything is working fine.

    The trouble is that I've built into my WebService a functionality by which any string larger than a certain amount of bytes (currently 16k, but it can be changed) gets broken into chunks and sent one chunk at a time. The WebService reassembles the chunks, calculates the MD5 of the entire string, compares it to an MD5 of the string calculated by the client that the client sent prior to sending all these chunks, and if they match, commits the transaction into the session.

    Let me also say that the above "chunking" process works on XML streams other than the one containing the image. For example, I tested it with a 1.7MB XML string that simply contained a bunch of ASCII nodes. The MD5s matched, I manually verified that the XML strings were identical on client and server, etc. So the source code is sound.

    However, when I combine the above two particular processes -- the XML string containing an image in base64 and the "chunking" process -- a strange thing occurs. The MD5s no longer match after "chunking." Additionally, the lengths of the strings according to the client and the server after the string has been transmitted to the server differ by about 4k (the client says it's around 358k; the server says it's 354k). But when I ask the client and server each to write a text file of the XML, they both write out identical files that compare (using fc from the command prompt) with no differences found.

    I'm officially stumped. Is it something having to do with base64? Is the base64 encoding getting conserved on the client side, but .NET's serialization is flattening it to ASCII for the server-side? Clearly such flattening doesn't matter, because the server can still put the image together without any errors. So if this is the problem, is there any way I can force this flattening to occur on the client-side prior to calculating an MD5 of the transmission?

    I've tried forcing the XML through System.Text.Encoding.ASCII.GetBytes() and GetString() for kicks, but it didn't change the size nor the above problems.

    If my theory is incorrect, please help me understand the problem and maybe what I could do to solve it given the above requirements.

    Any help is appreciated!

    Source: http://www.livejournal.com/community/csharp/36564.html

« Text formatting and System.Xml || Matrix Math Library »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home