/// <summary> /// Initiates sending of the specified HTTP request. /// </summary> /// <param name="connectionInfo">The connection.</param> /// <param name="stream">The content of the request.</param> /// <param name="timeout">The timeout of the operation.</param> private void InitiateSending(ConnectionInfo connectionInfo, Stream stream, int timeout) { Stream requestStream = null; try { // try to send it connectionInfo.HttpWebRequest.ContentLength = stream.Length; requestStream = connectionInfo.HttpWebRequest.GetRequestStream(); #if DEBUG byte[] content = new byte[(int)stream.Length]; GenuineUtility.ReadDataFromStream(stream, content, 0, content.Length); // this.ITransportContext.IEventLogger.Log(LogMessageCategory.TransportLayer, null, "HttpInvocationConnection.InitiateSending", // content, "The content of the request sent by the client application. Size: {0}.", stream.Length); stream = new MemoryStream(content); #endif GenuineUtility.CopyStreamToStream(stream, requestStream, (int)stream.Length); //connectionInfo.HttpWebRequest.BeginGetResponse(this._asyncCallback_onRequestCompleted, connectionInfo); HttpWebRequestCop webRequestCop = new HttpWebRequestCop(connectionInfo.HttpWebRequest, this._asyncCallback_onRequestCompleted, connectionInfo, this._httpAsynchronousRequestTimeout); } finally { if (requestStream != null) { requestStream.Close(); } } }
/// <summary> /// Initiates the HTTP request. /// </summary> /// <param name="httpWebRequest">The instance of the HttpWebRequest class.</param> /// <param name="inputStream">The input stream.</param> /// <param name="closed">The state event.</param> /// <param name="sender">Indicates whether the sender request is being sent.</param> /// <param name="asyncCallback">The callback.</param> /// <param name="dbgHttpClientConnection">The connection provided for debugging purposes.</param> private void LowLevel_InitiateHttpWebRequest(HttpWebRequest httpWebRequest, Stream inputStream, ManualResetEvent closed, bool sender, AsyncCallback asyncCallback, HttpClientConnection dbgHttpClientConnection) { BinaryLogWriter binaryLogWriter = this.ITransportContext.BinaryLogWriter; using(new ReaderAutoLocker(this._disposeLock)) { if (this._disposed) throw OperationException.WrapException(this._disposeReason); } Stream requestStream = null; try { if (! closed.WaitOne(this._webRequestInitiationTimeout, false)) throw GenuineExceptions.Get_Processing_LogicError("[0] Deadlock or a heavy load."); closed.Reset(); requestStream = httpWebRequest.GetRequestStream(); if (binaryLogWriter != null && binaryLogWriter[LogCategory.LowLevelTransport] > 0 ) { binaryLogWriter.WriteTransportContentEvent(LogCategory.LowLevelTransport, "HttpClientConnectionManager.LowLevel_InitiateHttpWebRequest", LogMessageType.LowLevelTransport_AsyncSendingInitiating, null, null, dbgHttpClientConnection == null ? null : dbgHttpClientConnection.Remote, binaryLogWriter[LogCategory.LowLevelTransport] > 1 ? inputStream : null, GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name, dbgHttpClientConnection == null ? -1 : dbgHttpClientConnection.DbgConnectionId, (int) inputStream.Length, null, null, null, "HTTP {0} Request is being sent. Size: {1}.", sender ? "SENDER" : "LISTENER", (int) inputStream.Length); } GenuineUtility.CopyStreamToStream(inputStream, requestStream, (int) inputStream.Length); this.IncreaseBytesSent((int) inputStream.Length); HttpWebRequestCop webRequestCop = new HttpWebRequestCop(httpWebRequest, asyncCallback, httpWebRequest, this._httpAsynchronousRequestTimeout); //httpWebRequest.BeginGetResponse(asyncCallback, httpWebRequest); } catch(Exception ex) { if (binaryLogWriter != null && binaryLogWriter[LogCategory.LowLevelTransport] > 0 ) { binaryLogWriter.WriteEvent(LogCategory.LowLevelTransport, "HttpClientConnectionManager.LowLevel_InitiateHttpWebRequest", LogMessageType.LowLevelTransport_AsyncSendingInitiating, ex, null, dbgHttpClientConnection == null ? null : dbgHttpClientConnection.Remote, null, GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name, null, null, dbgHttpClientConnection == null ? -1 : dbgHttpClientConnection.DbgConnectionId, 0, 0, 0, null, null, null, null, "Exception occurred while initiating HTTP request."); } try { httpWebRequest.Abort(); } catch(Exception) { } throw; } finally { try { if (requestStream != null) requestStream.Close(); } catch(Exception ex) { // ignore & warning if (binaryLogWriter != null && binaryLogWriter[LogCategory.LowLevelTransport] > 0 ) { binaryLogWriter.WriteEvent(LogCategory.LowLevelTransport, "HttpClientConnectionManager.LowLevel_InitiateHttpWebRequest", LogMessageType.LowLevelTransport_AsyncSendingInitiating, ex, null, dbgHttpClientConnection == null ? null : dbgHttpClientConnection.Remote, null, GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name, null, null, dbgHttpClientConnection == null ? -1 : dbgHttpClientConnection.DbgConnectionId, 0, 0, 0, null, null, null, null, "Can't close the stream!"); } } closed.Set(); } }