/// <summary>
        /// Parse the given exception.
        /// </summary>
        /// <param name="exc">Encountered exception.</param>
        /// <returns>Parsed exception.</returns>
        /// <exception cref="ArgumentException">Exception is not an InvalidOperationException</exception>
        /// <exception cref="ArgumentNullException">Excepion is null</exception>
        public static ActiveDirectoryParsedException Parse(Exception exc)
        {
            if (exc == null)
            {
                throw new ArgumentNullException("exc is null");
            }

            if (!(exc is InvalidOperationException))
            {
                throw new ArgumentException("exc is not of type InvalidOperationException");
            }

            var parsedException = new ActiveDirectoryParsedException();

            string messageToBeParsed = exc.Message;
            if (exc.InnerException != null)
            {
                messageToBeParsed = exc.InnerException.Message;
            }

            try
            {
                var stringReader = new StringReader(messageToBeParsed);
                var errorObject = XmlSerializer.Deserialize(stringReader) as XmlErrorResponse;
                parsedException = new ActiveDirectoryParsedException(errorObject);
            }
            catch (InvalidOperationException)
            {
            }

            if (String.IsNullOrEmpty(parsedException.Code))
            {
                parsedException.Code = messageToBeParsed;
            }

            return parsedException;
        }
        /// <summary>
        /// Method to handle binding redirection exception. This exception means that the 
        /// user's data is located in another data center. This exception's details returns
        /// several urls that may work in this case. At least one url is guaranteed to work
        /// So we need to get all the URLs and try them
        /// </summary>
        /// <param name="parsedException">The binding redirection exception we received</param>
        /// <param name="operation">The operation to try</param>
        private void HandleBindingRedirectionException(ActiveDirectoryParsedException parsedException, Action operation)
        {
            var urls = (from ed in parsedException.Values.ErrorDetail where ed.Name.StartsWith("Url") select ed.Value).ToList();

            // Go thru the error details name\value pair

            // Now try each URL
            foreach (string newUrl in urls)
            {
                // We permanantly change the dataservice to point to the new URL
                // as none of the operations will work on the current url
                Service = new DirectoryDataService(new Uri(string.Format("{0}/{1}", newUrl, Properties.FullTenantAddress)));

                // This adds the default required headers to each request
                AddHeaders();

                try
                {
                    // try the operation
                    operation();

                    // if the operation is successful, break out of the loop
                    // all the subsequent operations will go to the new URL
                    break;
                }
                catch (Exception)
                {
                    // nothing can be done, try next URL
                }
            }
        }