internal AsyncOrganizationServiceConfiguration(Uri serviceUri, bool enableProxyTypes, Assembly assembly)
 {
     try {
         this.service = new ServiceConfigurationWrapper <IWcfAsyncOrganizationService>(serviceUri, true);
         if (enableProxyTypes && assembly != null)
         {
             this.EnableProxyTypes(assembly);
         }
         else if (enableProxyTypes)
         {
             this.EnableProxyTypes();
         }
     } catch (InvalidOperationException ex2) {
         bool flag = true;
         System.Net.WebException ex = ex2.InnerException as System.Net.WebException;
         if (ex != null)
         {
             System.Net.HttpWebResponse httpWebResponse = ex.Response as System.Net.HttpWebResponse;
             if (httpWebResponse != null && httpWebResponse.StatusCode == System.Net.HttpStatusCode.Unauthorized)
             {
                 flag = !this.AdjustServiceEndpoint(serviceUri);
             }
         }
         if (flag)
         {
             throw;
         }
     }
 }
        private bool AdjustServiceEndpoint(Uri serviceUri)
        {
            Uri uri = RemoveOrgName(serviceUri);

            if (uri != null)
            {
                this.service = new ServiceConfigurationWrapper <IWcfAsyncOrganizationService>(uri);
                if (this.service != null && this.service.ServiceEndpoints != null)
                {
                    foreach (KeyValuePair <string, ServiceEndpoint> current in this.service.ServiceEndpoints)
                    {
                        current.Value.Address = new System.ServiceModel.EndpointAddressBuilder(current.Value.Address)
                        {
                            Uri = serviceUri
                        }.ToEndpointAddress();
                    }
                    return(true);
                }
            }
            return(false);
        }