ic3man7019
ic3man7019

Reputation: 711

What would cause a ColdFusion server to return a 500 error when sending XML data?

I am attempting to send XML data to a remote ColdFusion server using the code below:

[HttpPost]
        public ActionResult Index(Transmission t)
        {
            ViewBag.ErrorMessage = "";
            ViewBag.OtherMessage = "";
            ViewBag.ResponseHtml = "";

            //set request properties
            var request = (HttpWebRequest)WebRequest.Create("theUrl");
            request.ContentType = "application/xml";
            request.ProtocolVersion = HttpVersion.Version10;
            request.Method = "POST";
            request.Timeout = 60000;

            //serialize the ViewModel
            XmlSerializer ser = new XmlSerializer(typeof(Transmission));
            XmlWriterSettings xws = new XmlWriterSettings();
            XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("", "");
            xws.OmitXmlDeclaration = true; //omit the xml declaration line  
            Stream stream = new MemoryStream();
            StringBuilder sb = new StringBuilder();
            XmlWriter writer = XmlWriter.Create(sb, xws);
            ser.Serialize(writer, t, ns);

            using (StreamReader sr = new StreamReader(stream))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    sb.AppendLine(line);
                }
                byte[] postBytes = Encoding.UTF8.GetBytes(sb.ToString());
                request.ContentLength = postBytes.Length;

                try
                {
                    using (Stream requestStream = request.GetRequestStream())
                    {
                        requestStream.Write(postBytes, 0, postBytes.Length);
                        requestStream.Close();
                    }
                    using (var response = (HttpWebResponse)request.GetResponse())
                    {
                        ViewBag.ResponseHtml = response.ToString();
                        return View("Error"); //TODO: change this to success when I get the 500 error fixed
                    }

                }
                catch (Exception ex)
                {
                    ViewBag.ErrorMessage = ex.Message;
                    request.Abort();
                    return View("Error");
                }
            }    
        }

I have no access to the ColdFusion administrator, as it is a third-party vendor. According to a developer on their end, they are able to see transactions in their database logs, but I am getting a 500 error on my end. Is there something in the code I've posted that I should change, or would this be due to some setting on their side? The only information that I'm able to get is that it is a 500: Internal Server Error. When I put breakpoints in my code, the program throws an exception at this line: using (var response = (HttpWebResponse)request.GetResponse()).

Any help would be greatly appreciated. I would be happy to provide any further information necessary.

Upvotes: 0

Views: 607

Answers (1)

Aquitaine
Aquitaine

Reputation: 106

While the 500 error may be coming from the front end server, Coldfusion has a setting in CF Admin under 'settings' called 'Enable HTTP Status Codes.' When enabled, it will send a 500 along with a CF error to whatever the front end server is, and that server may be configured to obfuscate the details and not relay the CF content.

So while it is possible that it's not from CF, it is a common configuration for production services not to be sending CF stack traces. Their logs should still show the actual error, or you could ask them to disable this setting temporarily.

Upvotes: 1

Related Questions