Example #1
0
        public static void ThrowFinal(UDDIException e)
        {
            if (0 == Context.ApiVersionMajor)
            {
                Context.ApiVersionMajor = 2;
            }

            string versionedNamespace = (Context.ApiVersionMajor == 1 ? "urn:uddi-org:api" : "urn:uddi-org:api_v2");

            HttpContext.Current.Response.StatusCode      = 500;
            HttpContext.Current.Response.ContentType     = Config.GetString("Soap.ContentType", @"text/xml; charset=""utf-8""");
            HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;

            XmlTextWriter soapFault = new XmlTextWriter(HttpContext.Current.Response.Output);

            soapFault.WriteStartDocument();
            soapFault.WriteStartElement("soap", "Envelope", "http://schemas.xmlsoap.org/soap/envelope/");
            soapFault.WriteStartElement("soap", "Body", "http://schemas.xmlsoap.org/soap/envelope/");
            soapFault.WriteStartElement("soap", "Fault", "http://schemas.xmlsoap.org/soap/envelope/");
            soapFault.WriteElementString("soap:faultcode", "soap:Client");
            soapFault.WriteElementString("soap:faultstring", "");
            soapFault.WriteStartElement("soap:detail");
            soapFault.WriteStartElement("dispositionReport");
            soapFault.WriteAttributeString("generic", "", Context.ApiVersionMajor.ToString() + ".0");
            soapFault.WriteAttributeString("operator", "", Config.GetString("Operator"));
            soapFault.WriteAttributeString("xmlns", versionedNamespace);
            soapFault.WriteStartElement("result");
            soapFault.WriteAttributeString("errno", "", (( int )e.Number).ToString());
            soapFault.WriteStartElement("errInfo");
            soapFault.WriteAttributeString("errCode", "", e.Number.ToString());
            soapFault.WriteString(UDDI.Utility.XmlEncode(e.Message));
            soapFault.WriteEndElement();
            soapFault.WriteEndElement();
            soapFault.WriteEndElement();
            soapFault.WriteEndElement();
            soapFault.WriteEndElement();
            soapFault.WriteEndElement();
            soapFault.WriteEndElement();
            soapFault.WriteEndDocument();

            soapFault.Flush();

            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.Close();
            HttpContext.Current.Response.End();
        }
Example #2
0
        public static void Throw(Exception e)
        {
            Debug.Enter();

            //
            // If this is a UDDI exception get the error number
            // Otherwise map all other errors to E_fatalError
            //
            ErrorType et           = ErrorType.E_fatalError;
            string    debugMessage = "";

            if (e is UDDI.UDDIException)
            {
                et = (ErrorType)((UDDIException)e).Number;
            }
            else if (e is System.Data.SqlClient.SqlException)
            {
                //
                // SECURITY: SqlException's include stored procedure names
                // This information is flowing back to the client in the SOAPFault
                // information. This information should be logged and not returned.
                //
                System.Data.SqlClient.SqlException se = (System.Data.SqlClient.SqlException)e;

                //
                // Build a detailed message about the exception; this text is not sent back to the user.
                //
                debugMessage = "SQL Exception in " + se.Procedure +
                               " line " + se.LineNumber +
                               " [severity " + se.Class +
                               ", state " + se.State;

                debugMessage += ", server " + se.Server;
                debugMessage += "]";

                //
                // Is this one of our custom error messages?  If so, we'll masssage the
                // error code into one of the UDDIException error types (custom errors
                // are thrown as ErrorType + 50000).  Otherwise, we'll simply use
                // E_fatalError.
                //
                if (16 == se.Class)
                {
                    et = (ErrorType)(se.Number - 50000);
                }
                else
                {
                    //
                    // 739178 - See if this was a SQL deadlock issue.  If it was, then return an E_serverBusy error
                    // instead.  The 1205 number is a retrieved from sysmessages table in the masters database of
                    // SQL Server.  See the SQL Books Online for more information about 1205.
                    //
                    if (1205 == se.Number)
                    {
                        //
                        // Change the 'e' variable to a new exception; need to do this since e.Message
                        // is read-only.  Keep track of the original exception so we can log it.
                        //
                        Exception originalException = e;
                        e  = new UDDIException(ErrorType.E_busy, "ERROR_BUSY");
                        et = ErrorType.E_busy;

                        Debug.Write(SeverityType.Info, CategoryType.Data, "A deadlock exception has been converted to an E_busy exception.  The original exception was:\r\n" + originalException.ToString());
                    }
                    else
                    {
                        et = ErrorType.E_fatalError;
                    }
                }
            }

            //
            // Log this error message.
            //
            Debug.Write(SeverityType.Info, CategoryType.Data, "An exception occurred. Details Follow:\r\n" + e.ToString() + "\r\n\r\n" + debugMessage);

            //
            // if this is a V1.0 call, map any new V2.0 error codes to
            // v1.0 error codes
            //
            if (1 == Context.ApiVersionMajor)
            {
                switch (et)
                {
                case ErrorType.E_invalidValue:
                case ErrorType.E_valueNotAllowed:
                case ErrorType.E_invalidProjection:
                case ErrorType.E_assertionNotFound:
                case ErrorType.E_invalidCompletionStatus:
                case ErrorType.E_messageTooLarge:
                case ErrorType.E_transferAborted:
                case ErrorType.E_publisherCancelled:
                case ErrorType.E_requestDenied:
                case ErrorType.E_secretUnknown:
                    et = ErrorType.E_fatalError;
                    break;
                }
            }

            //
            // Construct a new instance of a disposition report
            //
            DispositionReport dr = new DispositionReport(et, e.Message);

            //
            // Serialize the disposition report to a stream and load into
            // a DOM.
            //
            XmlDocument doc = new XmlDocument();

            MemoryStream strm = new MemoryStream();

            // XmlSerializer serializer = new XmlSerializer( typeof( DispositionReport ) );
            XmlSerializer serializer = XmlSerializerManager.GetSerializer(typeof(DispositionReport));

            serializer.Serialize(strm, dr);
            strm.Position = 0;

            doc.Load(strm);

            //
            // Wrap the disposition report with a detail node.
            //
            XmlNode detail = doc.CreateNode(
                XmlNodeType.Element,
                SoapException.DetailElementName.Name,
                SoapException.DetailElementName.Namespace);

            detail.AppendChild(doc.FirstChild.NextSibling);

            //
            // Construct the SOAP exception using the dr XML
            // as details and the received Exception as the inner exception.
            //

            UDDIText uddiText = new UDDIText("ERROR_FATAL_ERROR");

            throw new UDDISoapException(uddiText.GetText(),
                                        SoapException.ClientFaultCode,
                                        "",
                                        detail,
                                        e);
        }