Sage.SData.Client.Core.SDataService.ReadAsync C# (CSharp) Method

ReadAsync() public method

public ReadAsync ( string url, object userState ) : void
url string
userState object
return void
        public void ReadAsync(string url, object userState)
        {
            Guard.ArgumentNotNull(url, "url");

            var operation = new RequestOperation(HttpMethod.Get);
            var request = new SDataRequest(url, operation)
                          {
                              UserName = UserName,
                              Password = Password,
                              Timeout = Timeout,
                              Cookies = Cookies,
                              UserAgent = UserAgent
                          };
            request.BeginGetResponse(
                asyncResult =>
                {
                    try
                    {
                        var response = request.EndGetResponse(asyncResult);

                        if (ReadCompleted != null)
                        {
                            var content = response.Content;

                            if (content is string && response.ContentType == MediaType.Xml)
                            {
                                try
                                {
                                    content = ReadSchema(response);
                                }
                                catch (XmlException)
                                {
                                }
                                catch (InvalidOperationException)
                                {
                                }
                            }

                            ReadCompleted(this, new ReadCompletedEventArgs(content, null, false, userState));
                        }
                    }
                    catch (SDataClientException)
                    {
                        throw;
                    }
                    catch (Exception ex)
                    {
                        if (ReadCompleted != null)
                        {
                            ReadCompleted(this, new ReadCompletedEventArgs(null, ex, false, userState));
                        }
                    }
                }, null);
        }