0

I have the following code, sometimes its fine but others it truncates the xml, so i think its something to do with the length as it just splits in the middle of an xml tag.

            using (WebResponse response = request.GetResponse())
            {
                using (Stream streamResponse = response.GetResponseStream())
                {
                    using (StreamReader rd = new StreamReader(streamResponse, Encoding.UTF8))
                    {
                        XmlSerializer serializer = new XmlSerializer(typeof(T));

                        string soapResult = rd.ReadToEnd();
                    }
                }
            }

Has anyone got any ideas why its doing this and what i can do to fix it?

EmC
  • 9
  • 2
  • 1
    Some of your properties in your classes and not matching the xml. I save the text in the stream reader to a file. Then check the file to see if data is being truncated or you are not getting everything you are expecting. Add an exception handler around the serialization and see if you are getting any errors. – jdweng Aug 27 '20 at 16:03
  • 1
    Thanks but i tried that and it still cuts off the xml after 15166 characters in the middle of a tag, i think the issue is before i read the data, so at the point of retrieval by the WebResponse. Any idea why the WebResponse would truncate data? and how i can avoid it? – EmC Aug 28 '20 at 08:19
  • 1
    There is no reason for the data to stop in the middle. You can use a sniffer like wireshark or fiddler to see what is happening. The only reason I can think 1) Something wrong at server 2) There is something wrong with the connection. TCP is used and max size of chunks is 1500 bytes which has a CRC. If CRC is wrong chunks will be resent and eventually data will stop. To check connection from cmd.exe use >Ping -t -l 65500 IP Which will send continuously with 65500 bytes. The large size will indicate if the connection is good. – jdweng Aug 28 '20 at 08:45

0 Answers0