private void BuildEntitySetResolver(IAsyncContinuation continuation)
        {
            if (string.IsNullOrEmpty(this.ServiceDocumentUri))
            {
                IEntitySetResolver defaultEntitySetResolver = new DefaultEntitySetResolver();
                this.CurrentWorkspace.EntitySetResolver = defaultEntitySetResolver;
                continuation.Continue();
            }
            else
            {
                WebRequest serviceDocRequest = WebRequest.Create(this.ServiceDocumentUri);
#if !SILVERLIGHT
                if (this.AuthenticationProvider.UseDefaultCredentials)
                {
                    serviceDocRequest.UseDefaultCredentials = true;
                }
                else if (this.AuthenticationProvider.GetAuthenticationCredentials() != null)
                {
                    serviceDocRequest.Credentials = this.AuthenticationProvider.GetAuthenticationCredentials();
                }

                IDictionary <string, string> authenticationHeaders = this.AuthenticationProvider.GetAuthenticationHeaders();
                if (authenticationHeaders != null)
                {
                    foreach (var header in authenticationHeaders)
                    {
                        serviceDocRequest.Headers[header.Key] = header.Value;
                    }
                }

                // we will set the timeout to 5 seconds to avoid waiting forever for a Service doc request to complete.
                serviceDocRequest.Timeout = 5000;
#endif
                serviceDocRequest.BeginGetResponse(
                    (asyncResult) =>
                {
                    try
                    {
                        XDocument serviceDocument               = XDocument.Load(serviceDocRequest.EndGetResponse(asyncResult).GetResponseStream());
                        IEntitySetResolver entitySetResolver    = this.ServiceDocumentParser.ParseServiceDocument(serviceDocument.Root);
                        this.CurrentWorkspace.EntitySetResolver = entitySetResolver;
                        continuation.Continue();
                    }
                    catch (WebException errorWhileDownload)
                    {
                        continuation.Fail(errorWhileDownload);
                    }
                },
                    null);
            }
        }
        private void BuildEntitySetResolver(IAsyncContinuation continuation)
        {
            if (string.IsNullOrEmpty(this.ServiceDocumentUri))
            {
                IEntitySetResolver defaultEntitySetResolver = new DefaultEntitySetResolver();
                this.CurrentWorkspace.EntitySetResolver = defaultEntitySetResolver;
                continuation.Continue();
            }
            else
            {
                WebRequest serviceDocRequest = WebRequest.Create(this.ServiceDocumentUri);
#if !SILVERLIGHT

                if (this.AuthenticationProvider.UseDefaultCredentials)
                {
                    serviceDocRequest.UseDefaultCredentials = true;
                }
                else if (this.AuthenticationProvider.GetAuthenticationCredentials() != null)
                {
                    serviceDocRequest.Credentials = this.AuthenticationProvider.GetAuthenticationCredentials();
                }

                IDictionary<string, string> authenticationHeaders = this.AuthenticationProvider.GetAuthenticationHeaders();
                if (authenticationHeaders != null)
                {
                    foreach (var header in authenticationHeaders)
                    {
                        serviceDocRequest.Headers[header.Key] = header.Value;
                    }
                }

                // we will set the timeout to 5 seconds to avoid waiting forever for a Service doc request to complete.
                serviceDocRequest.Timeout = 5000;
#endif
                serviceDocRequest.BeginGetResponse(
                    (asyncResult) =>
                    {
                        try
                        {
                            XDocument serviceDocument = XDocument.Load(serviceDocRequest.EndGetResponse(asyncResult).GetResponseStream());
                            IEntitySetResolver entitySetResolver = this.ServiceDocumentParser.ParseServiceDocument(serviceDocument.Root);
                            this.CurrentWorkspace.EntitySetResolver = entitySetResolver;
                            continuation.Continue();
                        }
                        catch (WebException errorWhileDownload)
                        {
                            continuation.Fail(errorWhileDownload);
                        }
                    },
                    null);
            }
        }