Пример #1
0
 private string FindRedirectAddress()
 {
     using (StringReader stringReader = new StringReader(this.responseText))
     {
         AutoDiscoverRequest.AutoDiscoverTracer.TraceDebug <object, EmailAddress>((long)this.GetHashCode(), "{0}: Trying to find if there is any redirect address in the response for email {1}.", TraceContext.Get(), this.emailAddress);
         XPathDocument  xpathDocument  = SafeXmlFactory.CreateXPathDocument(stringReader);
         XPathNavigator xpathNavigator = xpathDocument.CreateNavigator();
         xpathNavigator.MoveToChild(XPathNodeType.Element);
         XmlNamespaceManager xmlNamespaceManager = new XmlNamespaceManager(xpathNavigator.NameTable);
         xmlNamespaceManager.AddNamespace("rs", "http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a");
         string          xpath           = string.Format("//{0}:RedirectAddr", "rs");
         XPathExpression xpathExpression = xpathNavigator.Compile(xpath);
         xpathExpression.SetContext(xmlNamespaceManager);
         XPathNodeIterator xpathNodeIterator = xpathNavigator.Select(xpathExpression);
         if (xpathNodeIterator != null && xpathNodeIterator.Count != 0)
         {
             while (xpathNodeIterator.MoveNext())
             {
                 string.Format("{0}:RedirectAddr", "rs");
                 XPathNavigator xpathNavigator2 = xpathNodeIterator.Current;
                 if (xpathNavigator2 != null)
                 {
                     AutoDiscoverRequest.AutoDiscoverTracer.TraceDebug <object, string, EmailAddress>((long)this.GetHashCode(), "{0}: Found redirect address {1} in the response for original email {2}.", TraceContext.Get(), xpathNavigator2.Value, this.emailAddress);
                     return(xpathNavigator2.Value);
                 }
             }
         }
     }
     AutoDiscoverRequest.AutoDiscoverTracer.TraceDebug <object, EmailAddress, string>((long)this.GetHashCode(), "{0}: Could not find any nodes containing redirection address for email {1} in the auto discovery response: {2}", TraceContext.Get(), this.emailAddress, this.responseText);
     return(null);
 }
Пример #2
0
 private WebServiceUri FindWebServiceUrlForProtocol(string protocol)
 {
     using (StringReader stringReader = new StringReader(this.responseText))
     {
         AutoDiscoverRequest.AutoDiscoverTracer.TraceDebug <object, string>((long)this.GetHashCode(), "{0}: Trying to find web service Url from auto-discover response for protocol '{1}'", TraceContext.Get(), protocol);
         XPathDocument  xpathDocument  = SafeXmlFactory.CreateXPathDocument(stringReader);
         XPathNavigator xpathNavigator = xpathDocument.CreateNavigator();
         xpathNavigator.MoveToChild(XPathNodeType.Element);
         XmlNamespaceManager xmlNamespaceManager = new XmlNamespaceManager(xpathNavigator.NameTable);
         xmlNamespaceManager.AddNamespace("rs", "http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a");
         string          xpath           = string.Format("//{0}:Protocol[{0}:Type='{1}']", "rs", protocol);
         XPathExpression xpathExpression = xpathNavigator.Compile(xpath);
         xpathExpression.SetContext(xmlNamespaceManager);
         XPathNodeIterator xpathNodeIterator = xpathNavigator.Select(xpathExpression);
         if (xpathNodeIterator == null || xpathNodeIterator.Count == 0)
         {
             AutoDiscoverRequest.AutoDiscoverTracer.TraceError <object, string, string>((long)this.GetHashCode(), "{0}: could not find any nodes of protocol type '{1}' in the auto discover response: {2}.", TraceContext.Get(), protocol, this.responseText);
             return(null);
         }
         while (xpathNodeIterator.MoveNext())
         {
             string         xpath2          = string.Format("{0}:ASUrl", "rs");
             XPathNavigator xpathNavigator2 = xpathNodeIterator.Current.SelectSingleNode(xpath2, xmlNamespaceManager);
             if (xpathNavigator2 != null)
             {
                 string value = xpathNavigator2.Value;
                 if (value != null)
                 {
                     int serverVersion = 0;
                     if ("EXCH".Equals(protocol, StringComparison.OrdinalIgnoreCase))
                     {
                         string         xpath3          = string.Format("{0}:ServerVersion", "rs");
                         XPathNavigator xpathNavigator3 = xpathNodeIterator.Current.SelectSingleNode(xpath3, xmlNamespaceManager);
                         if (xpathNavigator3 != null)
                         {
                             string value2 = xpathNavigator3.Value;
                             if (!int.TryParse(value2, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out serverVersion))
                             {
                                 AutoDiscoverRequest.AutoDiscoverTracer.TraceError <object, string>((long)this.GetHashCode(), "{0}: ServerVersion '{1}' cannot be parsed as a hex number.", TraceContext.Get(), value2);
                             }
                         }
                     }
                     return(new WebServiceUri(value, protocol, this.uriSource, serverVersion));
                 }
             }
         }
     }
     return(null);
 }
Пример #3
0
 private string FindError()
 {
     using (StringReader stringReader = new StringReader(this.responseText))
     {
         AutoDiscoverRequest.AutoDiscoverTracer.TraceDebug <object, EmailAddress>((long)this.GetHashCode(), "{0}: Trying to find if there is any error in the response for email {1}.", TraceContext.Get(), this.emailAddress);
         XPathDocument  xpathDocument  = SafeXmlFactory.CreateXPathDocument(stringReader);
         XPathNavigator xpathNavigator = xpathDocument.CreateNavigator();
         xpathNavigator.MoveToChild(XPathNodeType.Element);
         XmlNamespaceManager xmlNamespaceManager = new XmlNamespaceManager(xpathNavigator.NameTable);
         xmlNamespaceManager.AddNamespace("rs", "http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006");
         XPathExpression xpathExpression = xpathNavigator.Compile(AutoDiscoverRequest.ErrorSearchString);
         xpathExpression.SetContext(xmlNamespaceManager);
         XPathNodeIterator xpathNodeIterator = xpathNavigator.Select(xpathExpression);
         if (xpathNodeIterator != null && xpathNodeIterator.Count != 0)
         {
             string text  = null;
             string text2 = null;
             if (xpathNodeIterator.MoveNext())
             {
                 XPathNavigator xpathNavigator2 = xpathNodeIterator.Current.SelectSingleNode(AutoDiscoverRequest.ErrorCodeString, xmlNamespaceManager);
                 if (xpathNavigator2 != null)
                 {
                     text = xpathNavigator2.Value;
                     AutoDiscoverRequest.AutoDiscoverTracer.TraceDebug <object, string, EmailAddress>((long)this.GetHashCode(), "{0}: Found error code {1} in the response for original email {2}.", TraceContext.Get(), text, this.emailAddress);
                 }
                 XPathNavigator xpathNavigator3 = xpathNodeIterator.Current.SelectSingleNode(AutoDiscoverRequest.ErrorMessageString, xmlNamespaceManager);
                 if (xpathNavigator3 != null)
                 {
                     text2 = xpathNavigator3.Value;
                     AutoDiscoverRequest.AutoDiscoverTracer.TraceDebug <object, string, EmailAddress>((long)this.GetHashCode(), "{0}: Found error message {1} in the response for original email {2}.", TraceContext.Get(), text2, this.emailAddress);
                 }
             }
             if (text != null)
             {
                 if (text2 != null)
                 {
                     return("ErrorCode=" + text + ", Message=" + text2);
                 }
                 return("ErrorCode=" + text);
             }
         }
     }
     AutoDiscoverRequest.AutoDiscoverTracer.TraceDebug <object, EmailAddress, string>((long)this.GetHashCode(), "{0}: Could not find any nodes containing erroremail {1} in the auto discovery response: {2}", TraceContext.Get(), this.emailAddress, this.responseText);
     return(null);
 }
Пример #4
0
        protected XPathDocument GetFederationMetadataXPathDocument(Uri partnerFederationMetadataEpr)
        {
            if (null == partnerFederationMetadataEpr)
            {
                throw new ArgumentNullException("PartnerFederationMetadataEpr");
            }
            this.WriteVerbose(Strings.RequestingFederationMetadataFromEndPoint(partnerFederationMetadataEpr.ToString()));
            Exception ex = null;
            string    s  = null;
            DateTime  t  = DateTime.UtcNow.Add(TimeSpan.FromMinutes(1.0));

            do
            {
                if (ex != null)
                {
                    this.WriteVerbose(Strings.FailedToRetrieveFederationMetadata(ex.ToString()));
                    Thread.Sleep(TimeSpan.FromSeconds(5.0));
                    ex = null;
                }
                using (PartnerFederationMetadata.TimeOutWebClient timeOutWebClient = new PartnerFederationMetadata.TimeOutWebClient(59000))
                {
                    timeOutWebClient.Credentials = CredentialCache.DefaultCredentials;
                    WebProxy webProxy = LiveConfiguration.GetWebProxy(this.WriteVerbose);
                    timeOutWebClient.Proxy = (webProxy ?? new WebProxy());
                    timeOutWebClient.Headers.Add(HttpRequestHeader.UserAgent, "MicrosoftExchangeFedTrustManagement");
                    try
                    {
                        s = timeOutWebClient.DownloadString(partnerFederationMetadataEpr);
                    }
                    catch (WebException ex2)
                    {
                        ex = ex2;
                    }
                    catch (IOException ex3)
                    {
                        ex = ex3;
                    }
                    catch (ProtocolViolationException ex4)
                    {
                        ex = ex4;
                    }
                }
            }while (ex != null && DateTime.UtcNow < t);
            if (ex != null)
            {
                throw new FederationMetadataException(Strings.ErrorAccessingFederationMetadata(ex.Message));
            }
            XPathDocument result = null;

            try
            {
                StringReader textReader = new StringReader(s);
                result = SafeXmlFactory.CreateXPathDocument(textReader);
            }
            catch (XmlException ex5)
            {
                throw new FederationMetadataException(Strings.ErrorInvalidFederationMetadata(ex5.Message));
            }
            catch (XPathException ex6)
            {
                throw new FederationMetadataException(Strings.ErrorInvalidFederationMetadata(ex6.Message));
            }
            return(result);
        }