EDN Admin
Well-known member
Ive done a lot of searching for how to fix this error, and I cant find whats different between everything else and my code. Basically what Im doing is connecting to a bizTalk .asp service, and its being sent fine, and is recieved fine. It uses streams to get back and forth, and if I were to write it out to a string, it works fine. If I pass the same stream into the constructor of another class that parses the stream to xml, it gives the error. Heres the code: <font size=2>
</font><font color="#008080" size=2>Encoding</font><font size=2> encoding = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>UTF8Encoding</font><font size=2>();
</font><font color="#0000ff" size=2>byte</font><font size=2>[] data = encoding.GetBytes(request);
</font><font color="#008000" size=2>// Prepare web request...
</font><font color="#008080" size=2>HttpWebRequest</font><font size=2> myRequest = (</font><font color="#008080" size=2>HttpWebRequest</font><font size=2>)</font><font color="#008080" size=2>WebRequest</font><font size=2>.Create(</font><font color="#0000ff" size=2>this</font><font size=2>.path); </font><font color="#008000" size=2>// connect to mustang
</font><font color="#008080" size=2>WebResponse</font><font size=2> response; </font><font color="#008000" size=2>// POSTed response
</font><font size=2>myRequest.Method = </font><font color="#800000" size=2>"POST"</font><font size=2>;
myRequest.ContentType = </font><font color="#800000" size=2>"text/xml"</font><font size=2>;
</font><font color="#008000" size=2>//myRequest.ContentLength = data.Length;
</font><font color="#008080" size=2>Stream</font><font size=2> newStream = myRequest.GetRequestStream();
</font><font color="#008000" size=2>// Send the data.
</font><font size=2>newStream.Write(data, 0, data.Length);
response = myRequest.GetResponse();
</font><font color="#008080" size=2>Stream</font><font size=2> resStream = response.GetResponseStream();
</font><font color="#008000" size=2>//encoding = Encoding.UTF8;
</font><font color="#008080" size=2>StreamReader</font><font size=2> read = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>StreamReader</font><font size=2>(resStream);
</font><font color="#0000ff" size=2>string</font><font size=2> line = read.ReadToEnd();
</font><font color="#008080" size=2>TextReader</font><font size=2> reader = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>StringReader</font><font size=2>(line);
resStream.Seek(0, </font><font color="#008080" size=2>SeekOrigin</font><font size=2>.Begin);
</font><font color="#008080" size=2>IMWebResponse</font><font size=2> webResponse = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>IMWebResponse</font><font size=2>(resStream);
resStream.Close();
newStream.Close();
</font><font color="#0000ff" size=2>return</font><font size=2> webResponse;</font>
<font size=2>Heres the important part in IMWebResponse</font> <font size=2><font color="#0000ff" size=2>
private</font><font size=2> </font><font color="#0000ff" size=2>void</font><font size=2> parseHeader(</font><font color="#008080" size=2>Stream</font><font size=2> xmlResponse, </font><font color="#008080" size=2>TextReader</font><font size=2> reader)
{
</font><font color="#008080" size=2>XmlDocument</font><font size=2> xDoc = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>XmlDocument</font><font size=2>();
xDoc.Load(reader); //heres where the error is thrown.
</font><font color="#008080" size=2>XmlNodeList</font><font size=2> xmlList = xDoc.SelectNodes(</font><font color="#800000" size=2>"PNAResponse/TransactionHeader"</font><font size=2>);
header.ErrorNumber = xmlList.Item(0).SelectSingleNode(</font><font color="#800000" size=2>"ErrorStatus"</font><font size=2>)[</font><font color="#800000" size=2>"ErrorNumber"</font><font size=2>].InnerText;
header.ErrorStatus = xmlList.Item(0).SelectSingleNode(</font><font color="#800000" size=2>"ErrorStatus"</font><font size=2>).InnerText;
header.TransID = xmlList.Item(0).SelectSingleNode(</font><font color="#800000" size=2>"TransactionID"</font><font size=2>).InnerText;
</font><font size=2>header.TimeStamp = </font><font color="#008080" size=2>DateTime</font><font size=2>.Parse(xmlList.Item(0).SelectSingleNode(</font><font color="#800000" size=2>"TimeStamp"</font><font size=2>).InnerText);</font><font color="#008000" size=2> </font><font size=2>
}
Ive been doing a lot of playing around with this code, but the original code was something copied and pasted. The original error was the root element is missing, but now with this current code the page wont actually load, it just kinda sits there trying to load. <a title="http://www.doublenatural.com/test.aspx http://www.doublenatural.com/test.aspx www.doublenatural.com/test.aspx is where you can see the lack of action. Its an interesting error, and Im having the darndest time figuring it out. Any thoughts? </font></font>
View the full article
</font><font color="#008080" size=2>Encoding</font><font size=2> encoding = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>UTF8Encoding</font><font size=2>();
</font><font color="#0000ff" size=2>byte</font><font size=2>[] data = encoding.GetBytes(request);
</font><font color="#008000" size=2>// Prepare web request...
</font><font color="#008080" size=2>HttpWebRequest</font><font size=2> myRequest = (</font><font color="#008080" size=2>HttpWebRequest</font><font size=2>)</font><font color="#008080" size=2>WebRequest</font><font size=2>.Create(</font><font color="#0000ff" size=2>this</font><font size=2>.path); </font><font color="#008000" size=2>// connect to mustang
</font><font color="#008080" size=2>WebResponse</font><font size=2> response; </font><font color="#008000" size=2>// POSTed response
</font><font size=2>myRequest.Method = </font><font color="#800000" size=2>"POST"</font><font size=2>;
myRequest.ContentType = </font><font color="#800000" size=2>"text/xml"</font><font size=2>;
</font><font color="#008000" size=2>//myRequest.ContentLength = data.Length;
</font><font color="#008080" size=2>Stream</font><font size=2> newStream = myRequest.GetRequestStream();
</font><font color="#008000" size=2>// Send the data.
</font><font size=2>newStream.Write(data, 0, data.Length);
response = myRequest.GetResponse();
</font><font color="#008080" size=2>Stream</font><font size=2> resStream = response.GetResponseStream();
</font><font color="#008000" size=2>//encoding = Encoding.UTF8;
</font><font color="#008080" size=2>StreamReader</font><font size=2> read = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>StreamReader</font><font size=2>(resStream);
</font><font color="#0000ff" size=2>string</font><font size=2> line = read.ReadToEnd();
</font><font color="#008080" size=2>TextReader</font><font size=2> reader = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>StringReader</font><font size=2>(line);
resStream.Seek(0, </font><font color="#008080" size=2>SeekOrigin</font><font size=2>.Begin);
</font><font color="#008080" size=2>IMWebResponse</font><font size=2> webResponse = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>IMWebResponse</font><font size=2>(resStream);
resStream.Close();
newStream.Close();
</font><font color="#0000ff" size=2>return</font><font size=2> webResponse;</font>
<font size=2>Heres the important part in IMWebResponse</font> <font size=2><font color="#0000ff" size=2>
private</font><font size=2> </font><font color="#0000ff" size=2>void</font><font size=2> parseHeader(</font><font color="#008080" size=2>Stream</font><font size=2> xmlResponse, </font><font color="#008080" size=2>TextReader</font><font size=2> reader)
{
</font><font color="#008080" size=2>XmlDocument</font><font size=2> xDoc = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>XmlDocument</font><font size=2>();
xDoc.Load(reader); //heres where the error is thrown.
</font><font color="#008080" size=2>XmlNodeList</font><font size=2> xmlList = xDoc.SelectNodes(</font><font color="#800000" size=2>"PNAResponse/TransactionHeader"</font><font size=2>);
header.ErrorNumber = xmlList.Item(0).SelectSingleNode(</font><font color="#800000" size=2>"ErrorStatus"</font><font size=2>)[</font><font color="#800000" size=2>"ErrorNumber"</font><font size=2>].InnerText;
header.ErrorStatus = xmlList.Item(0).SelectSingleNode(</font><font color="#800000" size=2>"ErrorStatus"</font><font size=2>).InnerText;
header.TransID = xmlList.Item(0).SelectSingleNode(</font><font color="#800000" size=2>"TransactionID"</font><font size=2>).InnerText;
</font><font size=2>header.TimeStamp = </font><font color="#008080" size=2>DateTime</font><font size=2>.Parse(xmlList.Item(0).SelectSingleNode(</font><font color="#800000" size=2>"TimeStamp"</font><font size=2>).InnerText);</font><font color="#008000" size=2> </font><font size=2>
}
Ive been doing a lot of playing around with this code, but the original code was something copied and pasted. The original error was the root element is missing, but now with this current code the page wont actually load, it just kinda sits there trying to load. <a title="http://www.doublenatural.com/test.aspx http://www.doublenatural.com/test.aspx www.doublenatural.com/test.aspx is where you can see the lack of action. Its an interesting error, and Im having the darndest time figuring it out. Any thoughts? </font></font>
View the full article