Avatar of CRCInfosys
CRCInfosys

asked on 

Error Sending XML Response in ASP.NET

I have a listener webpage designed in ASP.Net that receives XML documents then updates a database with the information. The webpage then is supposed to send a response stating whether the file was imported correctly or not as an XML document. However everytime i try to send the respone i get an error stating: "Thread was being aborted." My code is below.

Any ideas?
private void SendResponse(Boolean success, String errMessage)
        {
            XmlDocument outgoingXML = new XmlDocument();
            String payLoadID = Guid.NewGuid().ToString();
            String curDate = System.DateTime.Now.ToString();
 
            try
            {
                if (success == true)
                {
                    outgoingXML.LoadXml("<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE cXML SYSTEM \"http://xml.cXML.org/schemas/cXML/1.1.009/cXML.dtd\"><cXML payloadID=\"" + payLoadID + "\" xml:lang=\"en-US\" timestamp=\"" + curDate + "\"><Response><Status code=\"200\" text=\"OK\"/></Response></cXML>");
                }
                else
                {
                    outgoingXML.LoadXml("<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE cXML SYSTEM \"http://xml.cXML.org/schemas/cXML/1.1.009/cXML.dtd\"><cXML payloadID=\"" + payLoadID + "\" xml:lang=\"en-US\" timestamp=\"" + curDate + "\"><Response><Status code=\"500\" text=\"" + errMessage.ToString() + "\"/></Response></cXML>");
                }
                Response.Write(outgoingXML.OuterXml);
                Response.End();
            }
            catch (XmlException ex)
            {
                _status = "1;Error : XML Response " + ex.Message.Trim();
                System.IO.File.WriteAllText(_errorFile, _status);
            }
        }

Open in new window

Programming Languages-OtherASP.NET.NET Programming

Avatar of undefined
Last Comment
CRCInfosys
Avatar of Praveen Venu
Praveen Venu
Flag of India image

Response.End will always raise threadaborted exception

Instead of Response.End() use
HttpContext.Current.ApplicationInstance.CompleteRequest()

read more at
http://support.microsoft.com/kb/312629/

Avatar of Daniel Reynolds
Avatar of CRCInfosys
CRCInfosys

ASKER

Ok thanks praveenvenu that got the Web Page to send the response but instead of just sending the XML portion it is sending the entire page afterwords as well. How do i get it to simply send the XML portion? Below is what the response looks like:

Response:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE cXML SYSTEM "http://xml.cXML.org/schemas/cXML/1.1.009/cXML.dtd"[]><cXML payloadID="e4d1842b-4281-4d79-a0ff-12e67217072b" xml:lang="en-US" timestamp="1/28/2009 5:08:39 PM"><Response><Status code="200" text="OK" /></Response></cXML>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" > <head><title>

</title></head>
<body>
    <form name="form1" method="post" action="Four51Import.aspx" id="form1"> <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE2MTY2ODcyMjlkZI4DYNWGRsHbHVdxtYep8mlSyCZv" />

    <div>
   
    </div>
    </form>
</body>
</html>

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Praveen Venu
Praveen Venu
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of CRCInfosys
CRCInfosys

ASKER

Thanks, I didnt see that code behind the aspx.
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo