public DirectoryGraph(string tenantId, string accessToken, string dataContractVersion = "0.5", int defaultPageSize = 20)
        {
            this.dataContractVersion = dataContractVersion;
            this.DefaultPageSize = defaultPageSize;

            this.connectionUri = new Uri(string.Format(@"https://directory.windows.net/{0}", tenantId));
            this.dataService = new DirectoryDataServiceProxy(connectionUri);
            this.dataService.IgnoreResourceNotFoundException = true;

            this.accessToken = accessToken;

            this.dataService.SendingRequest += delegate(object sender1, SendingRequestEventArgs args)
            {
                ((HttpWebRequest)args.Request).Headers.Add(Constants.HeaderNameAuthorization, "Bearer " + this.accessToken);
                ((HttpWebRequest)args.Request).Headers.Add(Constants.HeaderNameDataContractVersion, dataContractVersion);
            };
        }
        /// <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(ErrorResponseEx parsedException, Action operation)
        {
            List<string> urls = new List<string>();

            // Go thru the error details name\value pair
            foreach (ErrorDetail ed in parsedException.Values)
            {
                // if the name is something like url1, url2 add it to the list of URLs
                if (ed.Item.StartsWith("url"))
                {
                    urls.Add(ed.Value);
                }
            }

            // 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
                dataService = new DirectoryDataServiceProxy(new Uri(newUrl));

                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
                }
            }
        }