Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

404 error while trying to load XML file from Request.InputStream - Trying to pull XML node value

$
0
0

Hi,

Im trying to select a node list from a xml file with no success.

Here is the code I'm working with:

C#

private void m_application_EndRequest( object sender, EventArgs e )
        {
            HttpApplication app = (HttpApplication) sender;
            HttpContext cnt = app.Context;
            int duration = Environment.TickCount - (int) cnt.Items["TickCount"];
            int requestLength = cnt.Request.TotalBytes;
            TimeSpan tickspan = TimeSpan.FromMilliseconds(duration);
            string timespan = tickspan.Minutes.ToString() + ":" + tickspan.Seconds.ToString() + "." + tickspan.Milliseconds.ToString();
            string userID = "Null";

            string path = cnt.Request.Headers["SOAPAction"];
            if ((path != null) && (path != string.Empty))
            {
                path = path.Replace("\"", string.Empty);

                XmlDocument inputstream = new XmlDocument();

                using (Stream receiveStream = cnt.Request.InputStream)
                {
                    receiveStream.Position = 0;

                    using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8))
                    {
                        inputstream.Load(readStream);
                    }
                }

                XmlNamespaceManager nsmanager = new XmlNamespaceManager(inputstream.NameTable);
                nsmanager.AddNamespace("soap", "http://www.w3.org/2003/05/soap-envelope");
                nsmanager.AddNamespace("CoPilotHeader", "http://copilot.na.fire.com/copilotfire");
                nsmanager.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
                nsmanager.AddNamespace("xsd", "http://www.w3.org/2001/XMLSchema");
                nsmanager.AddNamespace("df", "http://tempuri.org/");
                XmlNodeList xnlist = inputstream.DocumentElement.SelectNodes("/soap:Envelope/soap:Header/df:CoPilotHeader", nsmanager);

                userID = xnlist[0]["CmaToken"].InnerText;

            }
            else
            {
                try
                {
                    path = cnt.Request.Url.AbsoluteUri;
                }
                catch (NullReferenceException)
                {
                    path = string.Empty;
                }

                userID = "Null";
            }

            SrvLogging.LogPerformance( path, duration, cnt.Timestamp, -1,
                cnt.Request.ContentLength, Environment.MachineName, cnt.Request.HttpMethod,
                cnt.Response.Status, timespan, userID);
        }

Here is the SOAP/XML:

POST /FireServices/route.asmx HTTP/1.1
Host: cras.na.fire.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://copilot.na.fire.com/copilotfire/GetRoute"<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><CoPilotHeader xmlns="http://copilot.na.fire.com/copilotfire/"><CmaToken>string</CmaToken><ErrorString>string</ErrorString><RecordCount>int</RecordCount></CoPilotHeader></soap:Header><soap:Body><GetRoute xmlns="http://copilot.na.fire.com/copilotfire/"><routeToken>string</routeToken><routeNo>string</routeNo></GetRoute></soap:Body></soap:Envelope>

Thoughts? I'm getting a 404 error when trying to load the xml file with the cnt.Request.InputStream

The ultimate goal is to pull the CmaToken out into the UserID string.


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>