Exemplo n.º 1
0
        public static SyncronizationServiceError HandleError(SoapException soapException)
        {
            SyncronizationServiceError error     = null;
            XmlDocument         xml              = new XmlDocument();
            XmlNodeList         detailErrors     = null;
            XmlNamespaceManager nameSpaceManager = null;

            try
            {
                if (soapException.Detail.OuterXml.IndexOf("detail") > 0)
                {
                    nameSpaceManager = new XmlNamespaceManager(xml.NameTable);
                    xml.LoadXml(soapException.Detail.OuterXml);
                    nameSpaceManager = new XmlNamespaceManager(xml.NameTable);
                    nameSpaceManager.AddNamespace("tns", soapException.Node);
                    detailErrors = xml.SelectNodes("//tns:Error", nameSpaceManager);

                    foreach (XmlNode detailError in detailErrors)
                    {
                        error = new SyncronizationServiceError();

                        error.stackTrace = detailError.SelectSingleNode("./tns:ErrorStackTrace", nameSpaceManager).InnerText;

                        error.message = detailError.SelectSingleNode("./tns:ErrorMessage", nameSpaceManager).InnerText;

                        error.name = detailError.SelectSingleNode("./tns:ErrorSource", nameSpaceManager).InnerText;

                        string errorType = detailError.SelectSingleNode("./tns:ErrorType", nameSpaceManager).InnerText;
                        error.errorType = SyncronizationServiceError.eServiceErrorType.Undef;
                        if (!string.IsNullOrEmpty(errorType))
                        {
                            error.errorType = (SyncronizationServiceError.eServiceErrorType)
                                              Enum.Parse(typeof(SyncronizationServiceError.eServiceErrorType), errorType);
                        }
                        break;
                    }
                }
            }
            catch (Exception)
            {
            }
            return(error);
        }
Exemplo n.º 2
0
        public static SoapException RaiseException(string webServiceUri, SyncronizationServiceError error,
                                                   bool isServerError)
        {
            XmlDocument      xml = null;
            XmlQualifiedName faultCodeLocation = SoapException.ServerFaultCode;
            XmlNode          rootNode          = null;
            XmlNode          errorNode         = null;
            XmlNode          errorNumberNode   = null;
            XmlNode          errorMessageNode  = null;
            XmlNode          errorSourceNode   = null;
            XmlNode          errorStackNode    = null;
            SoapException    soapException     = null;

            try
            {
                if (error == null)
                {
                    return(new SoapException("web service failure with no trapped errors",
                                             SoapException.ServerFaultCode));
                }

                if (!isServerError)
                {
                    faultCodeLocation = SoapException.ClientFaultCode;
                }

                xml = new XmlDocument();

                rootNode = xml.CreateNode(XmlNodeType.Element,
                                          SoapException.DetailElementName.Name,
                                          SoapException.DetailElementName.Namespace);


                errorNode = xml.CreateNode(XmlNodeType.Element, "Error", webServiceUri);

                errorNumberNode           = xml.CreateNode(XmlNodeType.Element, "ErrorType", webServiceUri);
                errorNumberNode.InnerText = error.errorType.ToString();

                errorMessageNode           = xml.CreateNode(XmlNodeType.Element, "ErrorMessage", webServiceUri);
                errorMessageNode.InnerText = error.message;

                errorSourceNode           = xml.CreateNode(XmlNodeType.Element, "ErrorSource", webServiceUri);
                errorSourceNode.InnerText = error.name;

                errorStackNode           = xml.CreateNode(XmlNodeType.Element, "ErrorStackTrace", webServiceUri);
                errorStackNode.InnerText = error.stackTrace;

                errorNode.AppendChild(errorNumberNode);
                errorNode.AppendChild(errorMessageNode);
                errorNode.AppendChild(errorSourceNode);
                errorNode.AppendChild(errorStackNode);

                rootNode.AppendChild(errorNode);


                soapException = new SoapException("Web Service Failure", faultCodeLocation,
                                                  webServiceUri, rootNode);
            }
            catch
            {
            }

            return(soapException);
        }