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

8/22/2022 - Mon
Praveen Venu

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/

Daniel Reynolds

ASKER
CRCInfosys

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
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER CERTIFIED SOLUTION
Praveen Venu

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
CRCInfosys

Thanks, I didnt see that code behind the aspx.