Beispiel #1
0
        private static void ProcessSoapException(ref SoapException aException, out int aCode, out string aDescription)
        {
            if (aException.Message == "UPnPError")
            {
                if (!aException.Code.IsEmpty && (aException.Code.Name == "Client" || aException.Code.Name.EndsWith(":Client")))
                {
                    try
                    {
                        XmlNode             node      = aException.Detail;
                        XmlNamespaceManager nsmanager = new XmlNamespaceManager(node.OwnerDocument.NameTable);
                        nsmanager.AddNamespace("u", "urn:schemas-upnp-org:control-1-0");

                        XmlNode code        = node.SelectSingleNode("u:UPnPError/u:errorCode", nsmanager);
                        XmlNode description = node.SelectSingleNode("u:UPnPError/u:errorDescription", nsmanager);

                        if (code != null && description != null)
                        {
                            aCode        = int.Parse(code.FirstChild.Value);
                            aDescription = description.FirstChild.Value;
                            return;
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            aCode        = kCommsError;
            aDescription = aException.Message;
        }
Beispiel #2
0
        private void StepTypeProcessing(StepType stepType, SoapException ex, int timeOut)
        {
            switch (stepType)
            {
            case StepType.Normal:
            {
                break;
            }

            case StepType.Fault:
            {
                throw ex;
            }

            case StepType.NoResponse:
            {
                System.Threading.Thread.Sleep(timeOut);
                break;
            }

            default:
            {
                break;
            }
            }
        }
Beispiel #3
0
        Tuple <bool, string> Upload(byte[] sourceContents = null)
        {
            try
            {
                var targetUrl = GetTargetUrl(_targetFileName);

                if (sourceContents != null)
                {
                    WebClient client = new WebClient();
                    client.Credentials = Credentials;
                    byte[] data = client.UploadData(targetUrl, "PUT", sourceContents);
                }

                return(new Tuple <bool, string>(true, targetUrl));
            }
            catch (Exception ee)
            {
                string message = ee.ToString();
                if (ee is SoapException)
                {
                    SoapException soapExc = (SoapException)ee;
                    message += soapExc.Detail != null & soapExc.Detail.InnerText != null ? soapExc.Detail.InnerText : soapExc.Message;
                    //_log(soapExc.Detail.InnerText, LogType.Error);
                }
                //_log(message, LogType.Error);
                return(new Tuple <bool, string>(false, String.Empty));
            }
        }
Beispiel #4
0
        //***************************************************************************************

        #region DoorControl

        internal StepType AccessDoorTest(out SoapException ex, out int Timeout, string Token, bool UseExtendedTime, bool UseExtendedTimeSpecified, string AccessTime, string OpenTooLongTime, string PreAlarmTime, AccessDoorExtension Extension)
        {
            StepType res = StepType.None;

            Timeout = 0;
            ex      = null;
            bool   passed     = true;
            string logMessage = "";

            string tmpCommandName   = "AccessDoor";
            int    tmpCommandNumber = AccessDoor;

            //Get step list for command
            XmlNodeList m_testList = m_TestCommon.GetStepsForCommand(ServiceName + "." + tmpCommandName);

            if (m_testList.Count != 0)
            {
                //Get current step
                XmlNode test = m_testList[m_commandCount[tmpCommandNumber]];

                #region Analyze request

                //Token
                CommonCompare.StringCompare("RequestParameters/Token", "Token", Token, ref logMessage, ref passed, test);

                //UseExtendedTime
                if (CommonCompare.Exist2("RequestParameters/UseExtendedTime", "UseExtendedTime", UseExtendedTimeSpecified, ref logMessage, ref passed, test))
                {
                    CommonCompare.StringCompare("RequestParameters/UseExtendedTime", "UseExtendedTime", UseExtendedTime.ToString(), ref logMessage, ref passed, test);
                }

                //AccessTime
                CommonCompare.StringCompare("RequestParameters/AccessTime", "AccessTime", AccessTime, ref logMessage, ref passed, test);

                //OpenTooLongTime
                CommonCompare.StringCompare("RequestParameters/OpenTooLongTime", "OpenTooLongTime", OpenTooLongTime, ref logMessage, ref passed, test);

                //PreAlarmTime
                CommonCompare.StringCompare("RequestParameters/PreAlarmTime", "PreAlarmTime", PreAlarmTime, ref logMessage, ref passed, test);

                //Extension
                //TODO

                #endregion //Analyze request

                //Generate response
                res = m_TestCommon.GenerateResponseStepTypeVoid(test, out ex, out Timeout);

                //Log message
                m_TestCommon.writeToLog(test, logMessage, passed);

                Increment(m_testList.Count, tmpCommandNumber);
            }
            else
            {
                throw new SoapException("NO " + ServiceName + "." + tmpCommandName + " COMMAND IN SCRIPT", SoapException.ServerFaultCode);
            }
            return(res);
        }
Beispiel #5
0
        public static SoapException CreateSoapException(string uri,
                                                        string webServiceNamespace,
                                                        string errorMessage,
                                                        string errorNumber,
                                                        string errorSource,
                                                        EnumNetLocation errorLocation)
        {
            XmlQualifiedName faultCodeLocation = null;

            //Identify the location of the FaultCode
            if (errorLocation == EnumNetLocation.Client)
            {
                faultCodeLocation = SoapException.ClientFaultCode;
            }
            else
            {
                faultCodeLocation = SoapException.ServerFaultCode;
            }
            XmlDocument xmlDoc = new XmlDocument();
            //Create the Detail node
            XmlNode rootNode = xmlDoc.CreateNode(XmlNodeType.Element,
                                                 SoapException.DetailElementName.Name,
                                                 SoapException.DetailElementName.Namespace);
            //Build specific details for the SoapException
            //Add first child of detail XML element.
            XmlNode errorNode = xmlDoc.CreateNode(XmlNodeType.Element, XML_Error,
                                                  webServiceNamespace);
            //Create and set the value for the ErrorNumber node
            XmlNode errorNumberNode =
                xmlDoc.CreateNode(XmlNodeType.Element, XML_ErrorNumber,
                                  webServiceNamespace);

            errorNumberNode.InnerText = errorNumber;
            //Create and set the value for the ErrorMessage node
            XmlNode errorMessageNode = xmlDoc.CreateNode(XmlNodeType.Element,
                                                         XML_ErrorMessage,
                                                         webServiceNamespace);

            errorMessageNode.InnerText = errorMessage;
            //Create and set the value for the ErrorSource node
            XmlNode errorSourceNode =
                xmlDoc.CreateNode(XmlNodeType.Element, XML_ErrorSource,
                                  webServiceNamespace);

            errorSourceNode.InnerText = errorSource;
            //Append the Error child element nodes to the root detail node.
            errorNode.AppendChild(errorNumberNode);
            errorNode.AppendChild(errorMessageNode);
            errorNode.AppendChild(errorSourceNode);
            //Append the Detail node to the root node
            rootNode.AppendChild(errorNode);
            //Construct the exception
            SoapException soapEx = new SoapException(errorMessage,
                                                     faultCodeLocation, uri,
                                                     rootNode);

            //Raise the exception  back to the caller
            return(soapEx);
        }
        internal StepType GetEventSearchResultsTest(out FindEventResultList target, out SoapException ex, out int Timeout, string SearchToken, int MinResults, bool MinResultsSpecified, int MaxResults, bool MaxResultsSpecified, string WaitTime)
        {
            StepType res = StepType.None;

            Timeout = 0;
            ex      = null;
            target  = null;
            bool   passed     = true;
            string logMessage = "";

            string tmpCommandName   = "GetEventSearchResults";
            int    tmpCommandNumber = GetEventSearchResults;

            //Get step list for command
            XmlNodeList m_testList = TestCommon.GetStepsForCommand(ServiceName + "." + tmpCommandName);

            if (m_testList.Count != 0)
            {
                //Get current step
                XmlNode test = m_testList[CommandCount[tmpCommandNumber]];

                #region Analyze request

                //SearchToken
                CommonCompare.StringCompare("RequestParameters/SearchToken", "SearchToken", SearchToken, ref logMessage, ref passed, test);

                //MinResults
                if (CommonCompare.Exist2("RequestParameters/MinResults", "MinResults", MinResultsSpecified, ref logMessage, ref passed, test))
                {
                    CommonCompare.IntCompare("RequestParameters/MinResults", "MinResults", MinResults, ref logMessage, ref passed, test);
                }

                //MaxResults
                if (CommonCompare.Exist2("RequestParameters/MaxResults", "MaxResults", MaxResultsSpecified, ref logMessage, ref passed, test))
                {
                    CommonCompare.IntCompare("RequestParameters/MaxResults", "MaxResults", MaxResults, ref logMessage, ref passed, test);
                }

                //WaitTime
                CommonCompare.StringCompare("RequestParameters/WaitTime", "WaitTime", WaitTime, ref logMessage, ref passed, test);

                #endregion //Analyze request

                //Generate response
                object targetObj;
                res    = TestCommon.GenerateResponseStepTypeNotVoid(test, out targetObj, out ex, out Timeout, typeof(FindEventResultList));
                target = (FindEventResultList)targetObj;

                //Log message
                TestCommon.writeToLog(test, logMessage, passed);

                Increment(m_testList.Count, tmpCommandNumber);
            }
            else
            {
                throw new SoapException("NO " + ServiceName + "." + tmpCommandName + " COMMAND IN SCRIPT", SoapException.ServerFaultCode);
            }
            return(res);
        }
Beispiel #7
0
        /// <summary>
        /// 获取SoaException错误信息
        /// 此方法仅用于调用WebService的错误处理
        /// </summary>
        /// <param name="soapEx"></param>
        /// <param name="key">信息类型关键字:message、source、code其一</param>
        /// <returns>返当前错误信息</returns>
        public static string SoapExceptionInfo(SoapException soapEx, string key)
        {
            string result = "远程未返回信息!";

            XmlDocument doc          = new XmlDocument();
            string      errorNumber  = "";
            string      errorMessage = "";
            string      errorSource  = "";

            if (soapEx.Detail.OuterXml != null && soapEx.Detail.OuterXml != "")
            {
                doc.LoadXml(soapEx.Detail.OuterXml);
                XmlNode categoryNode = doc.DocumentElement.SelectSingleNode("Error");
                try
                {
                    errorNumber = categoryNode.SelectSingleNode("ErrorNumber").InnerText;
                }
                catch (Exception)
                {
                }

                try
                {
                    errorMessage = categoryNode.SelectSingleNode("ErrorMessage").InnerText;
                }
                catch (Exception)
                {
                }

                try
                {
                    errorSource = categoryNode.SelectSingleNode("ErrorSource").InnerText;
                }
                catch (Exception)
                {
                }
            }

            switch (key)
            {
            case "message":
                result = errorMessage;
                break;

            case "source":
                result = errorSource;
                break;

            case "code":
                result = errorNumber;
                break;

            default:
                result = errorMessage + "\r\n" + errorSource;
                break;
            }

            return(result);
        }
 public static bool IsVersionMismatch(SoapException e, string expectedEndpoint)
 {
     if (e.Code == SoapException.ClientFaultCode)
     {
         return(!e.Actor.EndsWith(expectedEndpoint, StringComparison.OrdinalIgnoreCase));
     }
     return(false);
 }
 private static void showSoapError(SoapException e, string msg)
 {
     MessageBoxWithHtml.showError(
         Constants.ERROR_CAPTION,
         e.Message + getExceptionDetailsLink("eSoap"),
         () => Clipboard.SetText(e.Detail.Name + ": " + e.Detail.Value + "\r\n\r\n" + getFullExceptionTextDetails(msg, e)),
         delegate { new ExceptionViewer(e.Detail.Name + ": " + e.Detail.Value, e).ShowDialog(); });
 }
 /// <summary>
 /// Creates a new <see cref="SoapOriginalException"/> instance.
 /// </summary>
 /// <param name="exception"></param>
 public SoapOriginalException(SoapException exception) : base(GetNodeText(exception.Detail, "Message"), DeserializeException(exception.Detail))
 {
     if (exception.Detail != null)
     {
         _type       = GetNodeText(exception.Detail, "Type");
         _stackTrace = GetNodeText(exception.Detail, "StackTrace");
     }
 }
Beispiel #11
0
        protected EventArgsError CreateEventArgsError(ref SoapException aException)
        {
            int    code;
            string description;

            ProcessSoapException(ref aException, out code, out description);
            return(new EventArgsError(code, description));
        }
Beispiel #12
0
        protected ServiceException CreateServiceException(ref SoapException aException)
        {
            int    code;
            string description;

            ProcessSoapException(ref aException, out code, out description);
            return(new ServiceException(code, description));
        }
Beispiel #13
0
        //***************************************************************************************

        #region Access Point

        internal StepType GetAccessPointInfoListTest(out AccessPointInfo[] target, out SoapException ex, out int Timeout, string[] TokenList)
        {
            StepType res = StepType.None;

            Timeout = 0;
            ex      = null;
            target  = null;
            bool   passed     = true;
            string logMessage = "";

            string tmpCommandName   = "GetAccessPointInfoList";
            int    tmpCommandNumber = GetAccessPointInfoList;

            //Get step list for command
            XmlNodeList m_testList = m_TestCommon.GetStepsForCommand(ServiceName + "." + tmpCommandName);

            if (m_testList.Count != 0)
            {
                //Get current step
                XmlNode test = m_testList[m_commandCount[tmpCommandNumber]];

                #region Serialization Temp
                //AccessPointInfo[] dsr = new AccessPointInfo[1];
                //dsr[0] = new AccessPointInfo();
                //dsr[0].token = "test";
                //dsr[0].Name = "name";
                //dsr[0].Entity = "Device";
                //dsr[0].Enabled = true;
                //dsr[0].Type = "not:Device";
                //XmlSerializer serializer = new XmlSerializer(typeof(AccessPointInfo[]));
                //XmlReader sr = XmlReader.Create(new StringReader(test.SelectNodes("ResponseParameters")[0].InnerXml));
                //TextWriter textWriter = new StreamWriter("d:\\2.txt");
                //serializer.Serialize(textWriter, dsr);
                #endregion //Serialization Temp

                #region Analyze request

                //TokenList
                CommonCompare.StringArrayCompare("RequestParameters/Token", "Token", TokenList, ref logMessage, ref passed, test);

                #endregion //Analyze request

                //Generate response
                object targetObj;
                res    = m_TestCommon.GenerateResponseStepTypeNotVoid(test, out targetObj, out ex, out Timeout, typeof(AccessPointInfo[]));
                target = (AccessPointInfo[])targetObj;

                //Log message
                m_TestCommon.writeToLog(test, logMessage, passed);

                Increment(m_testList.Count, tmpCommandNumber);
            }
            else
            {
                throw new SoapException("NO " + ServiceName + "." + tmpCommandName + " COMMAND IN SCRIPT", SoapException.ServerFaultCode);
            }
            return(res);
        }
 public static void ShowError(SoapException ex)
 {
     MessageBox.Show("Message: " + ex.Message + "\r\n" +
                     "Actor: " + ex.Actor + "\r\n" +
                     "Code: " + ex.Code + "\r\n" +
                     "Detail: " + ex.Detail.InnerText + "\r\n" +
                     "Source: " + ex.Source + "\r\n" +
                     "Stack: " + ex.StackTrace, "Unexpected Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
 }
Beispiel #15
0
        public void LogFault(SoapException fault)
        {
            string data = DateTime.UtcNow.ToLongDateString() + " " + fault.Code + " " + fault.Message + " " + fault.InnerException + " " + fault.StackTrace;

            using (FileStream fs = File.Open(FileName, FileMode.OpenOrCreate))
            {
                fs.Write(Encoding.ASCII.GetBytes(data), 0, data.Length);
            }
        }
        internal StepType GetDoorInfoListTest(out DoorInfo[] target, out SoapException ex, out int Timeout, string[] TokenList, int Limit, bool LimitSpecified, int Offset, bool OffsetSpecified)
        {
            StepType res = StepType.None;

            Timeout = 0;
            ex      = null;
            target  = null;
            bool   passed     = true;
            string logMessage = "";

            string tmpCommandName   = "GetDoorInfoList";
            int    tmpCommandNumber = GetDoorInfoList;

            //Get step list for command
            XmlNodeList m_testList = m_TestCommon.GetStepsForCommand(ServiceName + "." + tmpCommandName);

            if (m_testList.Count != 0)
            {
                //Get current step
                XmlNode test = m_testList[m_commandCount[tmpCommandNumber]];

                #region Analyze request

                //TokenList
                CommonCompare.StringArrayCompare("RequestParameters/Token", "Token", TokenList, ref logMessage, ref passed, test);

                //Limit
                if (CommonCompare.Exist2("RequestParameters/Limit", "Limit", LimitSpecified, ref logMessage, ref passed, test))
                {
                    CommonCompare.IntCompare("RequestParameters/Limit", "Limit", Limit, ref logMessage, ref passed, test);
                }

                //Offset
                if (CommonCompare.Exist2("RequestParameters/Offset", "Offset", OffsetSpecified, ref logMessage, ref passed, test))
                {
                    CommonCompare.IntCompare("RequestParameters/Offset", "Offset", Offset, ref logMessage, ref passed, test);
                }

                #endregion //Analyze request

                //Generate response
                object targetObj;
                res    = m_TestCommon.GenerateResponseStepTypeNotVoid(test, out targetObj, out ex, out Timeout, typeof(DoorInfo[]));
                target = (DoorInfo[])targetObj;

                //Log message
                m_TestCommon.writeToLog(test, logMessage, passed);

                Increment(m_testList.Count, tmpCommandNumber);
            }
            else
            {
                throw new SoapException("NO " + ServiceName + "." + tmpCommandName + " COMMAND IN SCRIPT", SoapException.ServerFaultCode);
            }
            return(res);
        }
Beispiel #17
0
        void OnEnter(Object source, EventArgs eventArgs)
        {
            HttpApplication app        = (HttpApplication)source;
            HttpContext     context    = app.Context;
            Stream          HttpStream = context.Request.InputStream;

            // Save the current position of stream.
            long posStream = HttpStream.Position;

            // If the request contains an HTTP_SOAPACTION
            // header, look at this message.
            if (context.Request.ServerVariables["HTTP_SOAPACTION"] == null)
            {
                return;
            }

            // Load the body of the HTTP message
            // into an XML document.
            XmlDocument dom = new XmlDocument();
            string      soapUser;
            string      soapPassword;

            try
            {
                dom.Load(HttpStream);

                // Reset the stream position.
                HttpStream.Position = posStream;

                // Bind to the Authentication header.
                soapUser =
                    dom.GetElementsByTagName("UserName").Item(0).InnerText;
                soapPassword =
                    dom.GetElementsByTagName("Password").Item(0).InnerText;
            }
            catch (Exception e)
            {
                // Reset the position of stream.
                HttpStream.Position = posStream;

                // Throw a SOAP exception.
                XmlQualifiedName name          = new XmlQualifiedName("Load");
                SoapException    soapException = new SoapException("Unable to read SOAP request", name, e);
                throw soapException;
            }

            // Raise the custom global.asax event.
            OnAuthenticate(new WebServiceAuthenticationEvent
                               (context, soapUser, soapPassword));
            var eee = new WebServiceAuthenticationEvent
                          (context, soapUser, soapPassword);

            //if (eee.User != null)
            eee.Context.User = eee.Principal;
            return;
        }
        //***************************************************************************************


        #region Events

        internal StepType FindEventsTest(out string target, out SoapException ex, out int Timeout, DateTime StartPoint, DateTime EndPoint, bool EndPointSpecified, SearchScope Scope, EventFilter SearchFilter, bool IncludeStartState, int MaxMatches, bool MaxMatchesSpecified, string KeepAliveTime)
        {
            StepType res = StepType.None;

            Timeout = 0;
            ex      = null;
            target  = null;
            bool   passed     = true;
            string logMessage = "";

            string tmpCommandName   = "FindEvents";
            int    tmpCommandNumber = FindEvents;

            //Get step list for command
            XmlNodeList m_testList = TestCommon.GetStepsForCommand(ServiceName + "." + tmpCommandName);

            if (m_testList.Count != 0)
            {
                //Get current step
                XmlNode test = m_testList[CommandCount[tmpCommandNumber]];

                #region Analyze request

                //KeepAliveTime
                CommonCompare.StringCompare("RequestParameters/KeepAliveTime", "KeepAliveTime", KeepAliveTime, ref logMessage, ref passed, test);

                //IncludedRecordings
                CommonCompare.StringCompare("RequestParameters/IncludedRecordings", "IncludedRecordings", Scope.IncludedRecordings[0], ref logMessage, ref passed, test);

                //StartPoint
                CommonCompare.StringCompare("RequestParameters/StartPoint", "StartPoint", XmlConvert.ToString(StartPoint, XmlDateTimeSerializationMode.Utc), ref logMessage, ref passed, test);

                //EndPoint
                CommonCompare.StringCompare("RequestParameters/EndPoint", "EndPoint", XmlConvert.ToString(EndPoint, XmlDateTimeSerializationMode.Utc), ref logMessage, ref passed, test);

                //IncludeStartState
                CommonCompare.StringCompare("RequestParameters/IncludeStartState", "IncludeStartState", IncludeStartState.ToString(), ref logMessage, ref passed, test);

                #endregion //Analyze request

                //Generate response
                object targetObj;
                res    = TestCommon.GenerateResponseStepTypeNotVoid(test, out targetObj, out ex, out Timeout, typeof(string));
                target = (string)targetObj;

                //Log message
                TestCommon.writeToLog(test, logMessage, passed);

                Increment(m_testList.Count, tmpCommandNumber);
            }
            else
            {
                throw new SoapException("NO " + ServiceName + "." + tmpCommandName + " COMMAND IN SCRIPT", SoapException.ServerFaultCode);
            }
            return(res);
        }
Beispiel #19
0
        internal StepType GetStatusTest(out ImagingStatus20 target, out SoapException ex, out int Timeout, string VideoSourceToken)
        {
            StepType res = StepType.None;

            Timeout = 0;
            ex      = null;
            bool   passed     = true;
            string logMessage = "";

            //Get step list for command
            XmlNodeList m_testList = m_TestCommon.GetStepsForCommand("Imaging20.GetStatus");

            if (m_testList != null)
            {
                //Get current step
                XmlNode test = m_testList[m_commandCount[GetStatus]];

                #region Serialization Temp
                //Imaging10.ImagingStatus dsr = new Imaging10.ImagingStatus();
                //dsr.FocusStatus = new Imaging10.FocusStatus();
                //dsr.FocusStatus.Position = 12;
                //dsr.FocusStatus.MoveStatus = Imaging10.MoveStatus.IDLE;
                //dsr.FocusStatus.Error = "Test";
                //XmlSerializer serializer = new XmlSerializer(typeof(Imaging10.ImagingStatus));
                ////XmlReader sr = XmlReader.Create(new StringReader(test.SelectNodes("ResponseParameters")[0].InnerXml));
                //TextWriter textWriter = new StreamWriter("c:\\2.txt");
                //serializer.Serialize(textWriter, dsr);
                #endregion //Serialization Temp

                #region Analyze request

                //VideoSourceToken
                CommonCompare.StringCompare("RequestParameters/VideoSourceToken", "VideoSourceToken", VideoSourceToken, ref logMessage, ref passed, test);

                #endregion //Analyze request

                //Generate response
                object targetObj;
                res    = m_TestCommon.GenerateResponseStepTypeNotVoid(test, out targetObj, out ex, out Timeout, typeof(ImagingStatus20));
                target = (ImagingStatus20)targetObj;

                //Log message
                m_TestCommon.writeToLog(test, logMessage, passed);

                Increment(m_testList.Count, GetStatus);
            }
            else
            {
                res     = StepType.None;
                Timeout = 0;
                target  = null;
                ex      = null;
                res     = StepType.None;
            }
            return(res);
        }
        internal static SoapException CreateSoapClientException(Exception clientException)
        {
            // Get the details node for the soap exception
            XmlNode detailsNode = GenerateSoapExceptionDetailsNode(clientException.Message, clientException.GetType().Name);

            // Create the Soap exception
            SoapException soapEx = new SoapException(clientException.Message, SoapException.ClientFaultCode, clientException.TargetSite.Name, detailsNode);

            return(soapEx);
        }
Beispiel #21
0
        /// <summary>
        /// Determina si una SoapException es de tipo funcional.
        /// </summary>
        /// <param name="psoapEx">SoapException.</param>
        /// <returns>Verdadero si la SoapException es de tipo funcional.</returns>
        public static bool IsFunctionalException(SoapException psoapEx)
        {
            string type = GetExceptionType(psoapEx);

            if (type == typeof(FunctionalException).FullName)
            {
                return(true);
            }
            return(false);
        }
Beispiel #22
0
        /// <summary>
        /// Parses a soap fault into an ApiException.
        /// </summary>
        /// <param name="soapex">The <see cref="SoapException"/>.</param>
        /// <returns>The <see cref="ApiException"/>.</returns>
        static public ApiException FromSoapException(SoapException soapex)
        {
            ErrorType errorType = new ErrorType();
            XmlNode   details   = soapex.Detail;

            XPathExpression expr;
            XPathNavigator  nav = details.CreateNavigator();

            System.Xml.XmlNamespaceManager nsmgr = new System.Xml.XmlNamespaceManager(details.OwnerDocument.NameTable);
            //nsmgr.AddNamespace("pfx", "urn:ebay:apis:eBLBaseComponents");

            expr = nav.Compile("/FaultDetail");
            expr.SetContext(nsmgr);

            XmlNode faultdet = XmlUtility.GetChildNode(nav, expr);

            if (faultdet != null)
            {
                nav = faultdet.CreateNavigator();
                errorType.ShortMessage = soapex.Message.Trim();

                expr = nav.Compile("Severity");
                expr.SetContext(nsmgr);

                if (XmlUtility.GetString(nav, expr).Trim() == "Warning")
                {
                    errorType.SeverityCode = SeverityCodeType.Warning;
                }
                else
                {
                    errorType.SeverityCode = SeverityCodeType.Error;
                }

                expr = nav.Compile("DetailedMessage");
                expr.SetContext(nsmgr);
                errorType.LongMessage = XmlUtility.GetString(nav, expr).Trim();

                expr = nav.Compile("ErrorCode");
                expr.SetContext(nsmgr);
                errorType.ErrorCode = XmlUtility.GetString(nav, expr).Trim();
            }
            else
            {
                errorType.SeverityCode = SeverityCodeType.Error;
                errorType.ShortMessage = soapex.Code.Name.Trim();
                errorType.LongMessage  = soapex.Message.Trim();
                errorType.ErrorCode    = "0";
            }

            ErrorTypeCollection etc = new ErrorTypeCollection();

            etc.Add(errorType);

            return(new ApiException(etc));
        }
 public static void ThrowIfVersionMismatch(SoapException e, string expectedEndpoint, string message, bool includeInnerException)
 {
     if (IsVersionMismatch(e, expectedEndpoint))
     {
         if (includeInnerException)
         {
             throw new SoapVersionMismatchException(message, e);
         }
         throw new SoapVersionMismatchException(message, null);
     }
 }
        //***************************************************************************************

        #region Recordings

        internal StepType FindRecordingsTest(out string target, out SoapException ex, out int Timeout, SearchScope Scope, int MaxMatches, bool MaxMatchesSpecified, string KeepAliveTime)
        {
            StepType res = StepType.None;

            Timeout = 0;
            ex      = null;
            target  = null;
            bool   passed     = true;
            string logMessage = "";

            string tmpCommandName   = "FindRecordings";
            int    tmpCommandNumber = FindRecordings;

            //Get step list for command
            XmlNodeList m_testList = TestCommon.GetStepsForCommand(ServiceName + "." + tmpCommandName);

            if (m_testList.Count != 0)
            {
                //Get current step
                XmlNode test = m_testList[CommandCount[tmpCommandNumber]];

                #region Analyze request

                //KeepAliveTime
                CommonCompare.StringCompare("RequestParameters/KeepAliveTime", "KeepAliveTime", KeepAliveTime, ref logMessage, ref passed, test);

                //MaxMatches
                if (CommonCompare.Exist2("RequestParameters/MaxMatches", "MaxMatches", MaxMatchesSpecified, ref logMessage, ref passed, test))
                {
                    CommonCompare.IntCompare("RequestParameters/MaxMatches", "MaxMatches", MaxMatches, ref logMessage, ref passed, test);
                }

                //RecordingInformationFilter
                CommonCompare.StringCompare("RequestParameters/RecordingInformationFilter", "RecordingInformationFilter", Scope.RecordingInformationFilter, ref logMessage, ref passed, test);


                #endregion //Analyze request

                //Generate response
                object targetObj;
                res    = TestCommon.GenerateResponseStepTypeNotVoid(test, out targetObj, out ex, out Timeout, typeof(string));
                target = (string)targetObj;

                //Log message
                TestCommon.writeToLog(test, logMessage, passed);

                Increment(m_testList.Count, tmpCommandNumber);
            }
            else
            {
                throw new SoapException("NO " + ServiceName + "." + tmpCommandName + " COMMAND IN SCRIPT", SoapException.ServerFaultCode);
            }
            return(res);
        }
    //
    //  METHOD      : ThrowSoapFault
    //  DESCRIPTION : Method used to throw soap fault.
    //  PARAMETERS  : XmlNode detail - Details of error log.
    //  RETURNS     : na
    //
    public void ThrowSoapFault(XmlNode detail)
    {
        //Throw the exception
        SoapException se = new SoapException("Invalid Input",
                                             SoapException.ClientFaultCode,
                                             Context.Request.Url.AbsoluteUri,
                                             detail);

        throw se;
        //here we throw the exception.
    }
        /// <summary>
        /// Verify SoapFaultDetail message.
        /// </summary>
        /// <param name="soapFault">A SoapException contains Soap fault message.</param>
        public void VerifySoapFaultDetail(SoapException soapFault)
        {
            bool             isSchemaRight = false;
            string           detailBody    = SchemaValidation.GetSoapFaultDetailBody(SchemaValidation.LastRawResponseXml.OuterXml);
            ValidationResult detailResult  = SchemaValidation.ValidateXml(this.Site, detailBody);

            isSchemaRight = detailResult.Equals(ValidationResult.Success);

            // If the errorSchema is right, R9 can be captured.
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-SITESS_R9");

            // Verify MS-SITESS requirement: MS-SITESS_R9
            Site.CaptureRequirementIfIsTrue(
                isSchemaRight,
                9,
                @"[In SOAPFaultDetails] [The SOAPFaultDetails is defined as:] <s:schema xmlns:s=""http://www.w3.org/2001/XMLSchema"" targetNamespace="" http://schemas.microsoft.com/sharepoint/soap"">
              <s:complexType name=""SOAPFaultDetails"">
              <s:sequence>
              <s:element name=""errorstring"" type=""s:string""/>
              <s:element name=""errorcode"" type=""s:string"" minOccurs=""0""/>
              </s:sequence>
              </s:complexType>
              </s:schema>");

            string errorCode = Common.ExtractErrorCodeFromSoapFault(soapFault);

            // If error code is empty, R422 can be verified.
            if (string.IsNullOrEmpty(errorCode))
            {
                // If the errorSchema is right, R422 can be captured.
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-SITESS_R422");

                // Verify MS-SITESS requirement: MS-SITESS_R422
                Site.CaptureRequirementIfIsTrue(
                    isSchemaRight,
                    422,
                    @"[In SOAPFaultDetails] This element [errorcode] is optional.");
            }

            // If error code is not empty, R421 can be verified.
            if (!string.IsNullOrEmpty(errorCode))
            {
                // If the errorSchema is right, R421 can be captured.
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-SITESS_R421, the error code is {0}.", errorCode);

                bool isVerify421 = errorCode.Length.Equals(10) && errorCode.StartsWith("0x", StringComparison.CurrentCulture);

                // Verify MS-SITESS requirement: MS-SITESS_R421
                Site.CaptureRequirementIfIsTrue(
                    isVerify421,
                    421,
                    @"[In SOAPFaultDetails] errorcode: The hexadecimal representation of a four-byte result code.");
            }
        }
Beispiel #27
0
        public string Estadisticas()
        {
            try
            {
                IlogicaViajes FLogica = FabricaLogica.GetLogicaViajes();
                List <Viajes> lista   = FLogica.ListarViajesTodos();
                XmlDocument   xmldoc  = new XmlDocument();

                xmldoc.LoadXml("<lista></lista>");

                foreach (Viajes v in lista)
                {
                    XmlNode nodoViaje = xmldoc.CreateNode(XmlNodeType.Element, "Viaje", "");

                    XmlNode nodoNumero = xmldoc.CreateNode(XmlNodeType.Element, "Número", "");
                    nodoNumero.InnerXml = v.numero.ToString();
                    nodoViaje.AppendChild(nodoNumero);

                    XmlNode nodoCiudadDestino = xmldoc.CreateNode(XmlNodeType.Element, "CiudadDestino", "");
                    nodoCiudadDestino.InnerXml = v.t.ciudad;
                    nodoViaje.AppendChild(nodoCiudadDestino);

                    XmlNode nodoPaisDestino = xmldoc.CreateNode(XmlNodeType.Element, "PaisDestino", "");
                    nodoPaisDestino.InnerXml = v.t.pais;
                    nodoViaje.AppendChild(nodoPaisDestino);

                    XmlNode nodoCompania = xmldoc.CreateNode(XmlNodeType.Element, "Compania", "");
                    nodoCompania.InnerXml = v.c.nombre;
                    nodoViaje.AppendChild(nodoCompania);

                    XmlNode nodoFechaPartida = xmldoc.CreateNode(XmlNodeType.Element, "FechaPartida", "");
                    nodoFechaPartida.InnerXml = v.partida.ToString();
                    nodoViaje.AppendChild(nodoFechaPartida);

                    xmldoc.DocumentElement.AppendChild(nodoViaje);
                }
                return(xmldoc.OuterXml);
            }
            catch (Exception ex)
            {
                XmlDocument unDoc      = new System.Xml.XmlDocument();
                XmlNode     noddoError = unDoc.CreateNode(XmlNodeType.Element, SoapException.DetailElementName.Name, SoapException.DetailElementName.Namespace);

                XmlNode nodeDetalle = unDoc.CreateNode(XmlNodeType.Element, "Error", "");
                nodeDetalle.InnerText = ex.Message;


                noddoError.AppendChild(nodeDetalle);

                SoapException miEx = new SoapException(ex.Message, SoapException.ClientFaultCode, Context.Request.Url.AbsolutePath, noddoError);

                throw miEx;
            }
        }
 /// <include file='Avalara.AvaTax.Adapter.Doc.xml' path='adapter/common/members[@name="InternalConstructor"]/*' />
 internal AvaTaxException(SoapException soapException)
 {
     if (soapException.Detail != null && soapException.Detail.HasChildNodes)
     {
         _details = soapException.Detail.InnerText;
     }
     _message      = soapException.Message;
     _faultCode    = soapException.Code;
     this.HelpLink = soapException.HelpLink;
     this.Source   = soapException.Actor;
 }
        private LocalizedException GetLiveDomainServicesAccessExceptionToThrow(SoapException exception)
        {
            int num;

            if (exception.Detail != null && exception.Detail.HasChildNodes && int.TryParse(exception.Detail.FirstChild.InnerText.Trim(), out num))
            {
                DomainError domainError = (DomainError)num;
                return(new LiveDomainServicesException(domainError, this.GetMessageFromDomainError(domainError, exception), exception));
            }
            return(new LiveDomainServicesException(Strings.ErrorLiveDomainServicesAccess(exception.Message), exception));
        }
Beispiel #30
0
 public static void ParseSoapExceptionSuksess(TestContext context)
 {
     try
     {
         _exception = new SoapException(Feilmelding());
     }
     catch
     {
         Assert.Fail();
     }
 }
Beispiel #31
0
	public int GetEmployeesCountError()
	{
		try
		{
			SqlConnection con = new SqlConnection(connectionString);

			// Make a deliberately faulty SQL string
			string sql = "INVALID_SQL COUNT(*) FROM Employees";
			SqlCommand cmd = new SqlCommand(sql, con);

			// Open the connection and get the value.
			cmd.Connection.Open();
			int numEmployees = -1;
			try
			{
				numEmployees = (int)cmd.ExecuteScalar();
			}
			finally
			{
				cmd.Connection.Close();
			}
			return numEmployees;
		}
		catch (Exception err)
		{
			// Create the detail information
			// an <ExceptionType> element with the type name.
			XmlDocument doc = new XmlDocument();
			XmlNode node = doc.CreateNode(
				XmlNodeType.Element, SoapException.DetailElementName.Name,
				SoapException.DetailElementName.Namespace);
			XmlNode child = doc.CreateNode(
				XmlNodeType.Element, "ExceptionType",
				SoapException.DetailElementName.Namespace);
			child.InnerText = err.GetType().ToString();
			node.AppendChild(child);

			// Create the custom SoapException.
			// Use the message from the original exception,
			// and add the detail information.
			SoapException soapErr = new SoapException(
				err.Message, SoapException.ServerFaultCode,
				Context.Request.Url.AbsoluteUri, node);

			// Throw the revised SoapException.
			throw soapErr;
		}
	}
Beispiel #32
0
    private void createSoapException(string errCode, string errSource, string errDesc)
    {
        // Build the detail element of the SOAP fault.
        System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
        System.Xml.XmlNode node = doc.CreateNode(XmlNodeType.Element,
             SoapException.DetailElementName.Name, SoapException.DetailElementName.Namespace);

        // Build specific details for the SoapException.
        // Add first child of detail XML element.
        System.Xml.XmlNode messageNode = doc.CreateNode(XmlNodeType.Element, "ErrorCode", "http://tempuri.org/");
        System.Xml.XmlNode messageTextNode = doc.CreateNode(XmlNodeType.Text, "ErrorCodeText", "http://tempuri.org/");
        messageTextNode.Value = errCode;
        messageNode.AppendChild(messageTextNode);

        // Add second child of detail XML element with an attribute.

        System.Xml.XmlNode sourceNode = doc.CreateNode(XmlNodeType.Element, "ErrorSource","http://tempuri.org/");
        System.Xml.XmlNode sourceTextNode = doc.CreateNode(XmlNodeType.Text, "ErrorSourceText","http://tempuri.org/");
        sourceTextNode.Value = errSource;
        sourceNode.AppendChild(sourceTextNode);

        // Add third child of detail XML element with an attribute.

        System.Xml.XmlNode descrNode = doc.CreateNode(XmlNodeType.Element, "ErrorDescription","http://tempuri.org/");
        System.Xml.XmlNode descrTextNode = doc.CreateNode(XmlNodeType.Text, "ErrorDecriptionText","http://tempuri.org/");
        descrTextNode.Value = errDesc;
        descrNode.AppendChild(descrTextNode);

        // Append the three child elements to the node.
        node.AppendChild(messageNode);
        node.AppendChild(sourceNode);
        node.AppendChild(descrNode);

        //Throw the exception
        SoapException se = new SoapException("Fault occurred",SoapException.ClientFaultCode,Context.Request.Url.AbsoluteUri,node);
        throw se;
    }