/// <summary> /// /// </summary> /// <param name="requestContext"></param> /// <returns></returns> protected virtual void HandleRequestResponseStream(WebRequestContext requestContext) { if (!requestContext.IsInError && null != requestContext.Response) { try { requestContext.RequestState = new WebRequestState(requestContext.Response.GetResponseStream()); if (!requestContext.IsAsync) { while (0 < requestContext.ReadContent()) { requestContext.WriteContent(); } return; } requestContext.BeginReadContent(new AsyncCallback(BeginReadContentCallback)); } catch (Exception ex) { requestContext.HandleThrownException(ex); RaiseFaultedEvent(requestContext); } } }
/// <summary> /// /// </summary> /// <param name="requestContext"></param> protected virtual void HandleWriteContentToRequestStream(WebRequestContext requestContext) { if (!requestContext.IsInError && null != requestContext.RequestState) { try { if (!requestContext.IsAsync) { _bytesRead = 0; _totalBytesRead = 0L; _byteBuffer = new byte[requestContext.BufferSize]; while (0 < (_bytesRead = requestContext.Content.Read(_byteBuffer, 0, _byteBuffer.Length))) { _totalBytesRead += _bytesRead; requestContext.RequestState.SourceStream.Write(_byteBuffer, 0, _bytesRead); } return; } requestContext.BeginReadContent(new AsyncCallback(BeginReadContentCallback)); } catch (Exception ex) { requestContext.HandleThrownException(ex); RaiseFaultedEvent(requestContext); } } }
/// <summary> /// /// </summary> /// <param name="requestContext"></param> /// <returns></returns> protected virtual void HandleRequestResponse(WebRequestContext requestContext) { if (!requestContext.IsInError) { try { if (!requestContext.IsAsync) { requestContext.Response = requestContext.Request.GetResponse(); return; } requestContext.Request.BeginGetResponse(new AsyncCallback(BeginGetResponseCallback), requestContext); } catch (Exception ex) { requestContext.HandleThrownException(ex); RaiseFaultedEvent(requestContext); } } }