/// <summary> /// Callback used to process server response. /// </summary> /// <param name="asynchronousResult">Server response state.</param> protected void GetResponseCallback(IAsyncResult asynchronousResult) { SendingEventArgs args = new SendingEventArgs(); args.ResultId = _resultId; try { WebRequest webRequest = (WebRequest)asynchronousResult.AsyncState; HttpWebResponse response; response = (HttpWebResponse)webRequest.EndGetResponse(asynchronousResult); Stream streamResponse = response.GetResponseStream(); StreamReader streamReader = new StreamReader(streamResponse); string Response = streamReader.ReadToEnd(); byte[] bytes = Encoding.UTF8.GetBytes(Response); StringBuilder builder = new StringBuilder(); foreach (var i in bytes) { builder.Append(i.ToString()); } string temp = builder.ToString(); if (temp == "0001") { args.Status = SendingEventArgs.SendingStatus.Sent; } else { args.Status = SendingEventArgs.SendingStatus.ServerError; } streamResponse.Close(); streamReader.Close(); response.Close(); } catch (WebException e) { if (e.Status == WebExceptionStatus.RequestCanceled) { args.Status = SendingEventArgs.SendingStatus.Canceled; } else { args.Status = SendingEventArgs.SendingStatus.UnknownError; } } finally { EventHandler handler = SendingCompleted; if (handler != null) { handler(this, args); } } }
/// <summary> /// Callback used to process server response. /// </summary> /// <param name="asynchronousResult">Server response state.</param> protected void GetResponseCallback(IAsyncResult asynchronousResult) { SendingEventArgs args = new SendingEventArgs(); args.ResultId = _resultId; try { WebRequest webRequest = (WebRequest)asynchronousResult.AsyncState; HttpWebResponse response; response = (HttpWebResponse)webRequest.EndGetResponse(asynchronousResult); Stream streamResponse = response.GetResponseStream(); StreamReader streamReader = new StreamReader(streamResponse); string Response = streamReader.ReadToEnd(); byte[] bytes = Encoding.UTF8.GetBytes(Response); StringBuilder builder = new StringBuilder(); foreach (var i in bytes) builder.Append(i.ToString()); string temp = builder.ToString(); if (temp == "0001") { args.Status = SendingEventArgs.SendingStatus.Sent; } else { args.Status = SendingEventArgs.SendingStatus.ServerError; } streamResponse.Close(); streamReader.Close(); response.Close(); } catch (WebException e) { if (e.Status == WebExceptionStatus.RequestCanceled) { args.Status = SendingEventArgs.SendingStatus.Canceled; } else { args.Status = SendingEventArgs.SendingStatus.UnknownError; } } finally { EventHandler handler = SendingCompleted; if (handler != null) handler(this, args); } }