public async Task SendRequestAsync(Message message, TimeoutHelper timeoutHelper) { _timeoutHelper = timeoutHelper; _factory.ApplyManualAddressing(ref _to, ref _via, message); _httpRequestMessage = await _channel.GetHttpRequestMessageAsync(_to, _via, _timeoutHelper.CancellationToken); Message request = message; try { if (_channel.State != CommunicationState.Opened) { // if we were aborted while getting our request or doing correlation, // we need to abort the web request and bail Cleanup(); _channel.ThrowIfDisposedOrNotOpen(); } HttpOutput httpOutput = HttpOutput.CreateHttpOutput(_httpRequestMessage, _factory, request, _factory.IsChannelBindingSupportEnabled, _factory.GetHttpClient(), _factory._authenticationScheme, _timeoutHelper); bool success = false; try { _httpResponseMessageTask = await httpOutput.SendAsync(_httpRequestMessage); //this.channelBinding = httpOutput.TakeChannelBinding(); await httpOutput.CloseAsync(); success = true; } finally { if (!success) { httpOutput.Abort(HttpAbortReason.Aborted); } } } finally { if (!object.ReferenceEquals(request, message)) { request.Close(); } } }
protected override async Task OnReplyAsync(Message message, CancellationToken token) { Message responseMessage = message; try { bool closeOutputAfterReply = PrepareReply(ref responseMessage); httpOutput = this.GetHttpOutput(message); await httpOutput.SendAsync(token); if (closeOutputAfterReply) { await httpOutput.CloseAsync(); } } finally { if (message != null && !object.ReferenceEquals(message, responseMessage)) { responseMessage.Close(); } } }