internal static bool GetUcwaUrlFromHttpWebResponse(HttpWebResponse response, ICredentials credentials, int redirectCount, out string ucwaUrl)
 {
     ucwaUrl = string.Empty;
     try
     {
         using (Stream responseStream = response.GetResponseStream())
         {
             using (StreamReader streamReader = new StreamReader(responseStream))
             {
                 XmlDocument xmlDocument = new XmlDocument();
                 xmlDocument.LoadXml(streamReader.ReadToEnd());
                 using (XmlNodeList xmlNodeList = xmlDocument.SelectNodes("AutodiscoverResponse/User/Link"))
                 {
                     if (xmlNodeList.Count == 0)
                     {
                         return(false);
                     }
                     string redirectUrl = LyncAutodiscoverWorker.GetRedirectUrl(xmlNodeList);
                     if (!string.IsNullOrEmpty(redirectUrl))
                     {
                         ucwaUrl = LyncAutodiscoverWorker.ExecuteAuthenticatedLyncAutodiscoverRedirect(redirectUrl, credentials, redirectCount + 1);
                     }
                     else
                     {
                         ucwaUrl = LyncAutodiscoverWorker.GetTargetAttributeValue(xmlNodeList, "href", "token", "Internal/Ucwa");
                         if (string.IsNullOrEmpty(ucwaUrl))
                         {
                             ucwaUrl = LyncAutodiscoverWorker.GetTargetAttributeValue(xmlNodeList, "href", "token", "External/Ucwa");
                         }
                     }
                 }
             }
         }
     }
     catch (Exception)
     {
         return(false);
     }
     return(true);
 }
 internal static bool GetAuthenticatedAutodiscoverEndpointFromHttpWebResponse(HttpWebResponse response, int redirectCount, out string endpoint)
 {
     endpoint = string.Empty;
     try
     {
         using (Stream responseStream = response.GetResponseStream())
         {
             using (StreamReader streamReader = new StreamReader(responseStream))
             {
                 XmlDocument xmlDocument = new XmlDocument();
                 xmlDocument.LoadXml(streamReader.ReadToEnd());
                 using (XmlNodeList xmlNodeList = xmlDocument.SelectNodes("AutodiscoverResponse/Root/Link"))
                 {
                     if (xmlNodeList.Count == 0)
                     {
                         return(false);
                     }
                     string redirectUrl = LyncAutodiscoverWorker.GetRedirectUrl(xmlNodeList);
                     if (!string.IsNullOrEmpty(redirectUrl))
                     {
                         endpoint = LyncAutodiscoverWorker.ExecuteAnonymousLyncAutodiscoverRedirect(redirectUrl, redirectCount + 1);
                     }
                     else
                     {
                         endpoint = LyncAutodiscoverWorker.GetTargetAttributeValue(xmlNodeList, "href", "token", "OAuth");
                     }
                 }
             }
         }
     }
     catch (Exception)
     {
         return(false);
     }
     return(true);
 }