public bool EnableDelayedAccept(HttpOutput output)
 {
     if (base.IsAtEof)
     {
         return false;
     }
     this.httpOutput = output;
     return true;
 }
Exemple #2
0
        public bool EnableDelayedAccept(HttpOutput output, bool closeHttpOutput)
        {
            if (IsAtEof)
            {
                return false;
            }

            this.closeHttpOutput = closeHttpOutput;
            this.httpOutput = output;
            return true;
        }
Exemple #3
0
 public WebRequestOutputStream(Stream requestStream, HttpWebRequest httpWebRequest, HttpOutput httpOutput)
     : base(requestStream)
 {
     this.httpWebRequest = httpWebRequest;
     this.httpOutput = httpOutput;
 }
Exemple #4
0
                public GetOutputStreamAsyncResult(HttpWebRequest httpWebRequest, HttpOutput httpOutput, AsyncCallback callback, object state)
                    : base(callback, state)
                {
                    this.httpWebRequest = httpWebRequest;
                    this.httpOutput = httpOutput;

                    IAsyncResult result = null;
                    try
                    {
                        result = httpWebRequest.BeginGetRequestStream(onGetRequestStream, this);
                    }
                    catch (WebException webException)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(HttpChannelUtilities.CreateRequestWebException(webException, httpWebRequest, httpOutput.abortReason));
                    }

                    if (result.CompletedSynchronously)
                    {
                        CompleteGetRequestStream(result);
                        base.Complete(true);
                    }
                }
Exemple #5
0
            public SendAsyncResult(HttpOutput httpOutput, HttpResponseMessage httpResponseMessage, bool suppressEntityBody, TimeSpan timeout, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.httpOutput = httpOutput;
                this.httpResponseMessage = httpResponseMessage;
                this.suppressEntityBody = suppressEntityBody;

                if (suppressEntityBody)
                {
                    if (httpOutput.isRequest)
                    {
                        httpOutput.SetContentLength(0);
                        this.httpOutput.TraceSend();
                        this.httpOutput.LogMessage();
                        base.Complete(true);
                        return;
                    }
                }

                this.timeoutHelper = new TimeoutHelper(timeout);
                Send();
            }
Exemple #6
0
            public WriteStreamedMessageAsyncResult(TimeSpan timeout, HttpOutput httpOutput, HttpResponseMessage httpResponseMessage, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.httpResponseMessage = httpResponseMessage;
                this.httpOutput = httpOutput;
                httpOutput.outputStream = httpOutput.GetWrappedOutputStream();

                // Since HTTP streams don't support timeouts, we can't just use TimeoutStream here. 
                // Rather, we need to run a timer to bound the overall operation
                if (onStreamSendTimeout == null)
                {
                    onStreamSendTimeout = new Action<object>(OnStreamSendTimeout);
                }
                this.SetTimer(timeout);

                bool completeSelf = false;
                bool throwing = true;

                try
                {
                    completeSelf = HandleWriteStreamedMessage(null);
                    throwing = false;
                }
                finally
                {
                    if (completeSelf || throwing)
                    {
                        this.sendTimer.Cancel();
                    }
                }

                if (completeSelf)
                {
                    this.Complete(true);
                }
            }
        internal void SendResponseAndClose(HttpResponseMessage httpResponseMessage)
        {
            if (this.TryInitiateReply())
            {
                // Send the response message.
                try
                {
                    if (this.httpOutput == null)
                    {
                        this.httpOutput = this.GetHttpOutputCore(new NullMessage());
                    }
                    this.httpOutput.Send(httpResponseMessage, this.DefaultSendTimeout);
                }
                catch (Exception ex)
                {
                    if (Fx.IsFatal(ex))
                    {
                        throw;
                    }

                    DiagnosticUtility.TraceHandledException(ex, TraceEventType.Information);
                }
            }
            
            // Close the request context.
            try
            {
                this.Close(); // this also closes the HttpOutput
            }
            catch (Exception ex)
            {
                if (Fx.IsFatal(ex))
                {
                    throw;
                }

                DiagnosticUtility.TraceHandledException(ex, TraceEventType.Information);
            }
        }
        bool PrepareReply(ref Message message)
        {
            bool closeOnReceivedEof = false;

            // null means we're done
            if (message == null)
            {
                // A null message means either a one-way request or that the service operation returned null and
                // hence we can close the HttpOutput. By default we keep the HttpOutput open to allow the writing to the output 
                // even after the HttpInput EOF is received and the HttpOutput will be closed only on close of the HttpRequestContext.
                closeOnReceivedEof = true;
                message = CreateAckMessage(HttpStatusCode.Accepted, string.Empty);
            }

            if (!listener.ManualAddressing)
            {
                if (message.Version.Addressing == AddressingVersion.WSAddressingAugust2004)
                {
                    if (message.Headers.To == null ||
                        listener.AnonymousUriPrefixMatcher == null ||
                        !listener.AnonymousUriPrefixMatcher.IsAnonymousUri(message.Headers.To))
                    {
                        message.Headers.To = message.Version.Addressing.AnonymousUri;
                    }
                }
                else if (message.Version.Addressing == AddressingVersion.WSAddressing10
                    || message.Version.Addressing == AddressingVersion.None)
                {
                    if (message.Headers.To != null &&
                        (listener.AnonymousUriPrefixMatcher == null ||
                        !listener.AnonymousUriPrefixMatcher.IsAnonymousUri(message.Headers.To)))
                    {
                        message.Headers.To = null;
                    }
                }
                else
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                        new ProtocolException(SR.GetString(SR.AddressingVersionNotSupported, message.Version.Addressing)));
                }
            }

            message.Properties.AllowOutputBatching = false;
            this.httpOutput = GetHttpOutputCore(message);

            // Reuse the HttpInput we got previously.
            HttpInput input = this.httpPipeline.HttpInput;
            if (input != null)
            {
                HttpDelayedAcceptStream requestStream = input.GetInputStream(false) as HttpDelayedAcceptStream;
                if (requestStream != null && TransferModeHelper.IsRequestStreamed(listener.TransferMode)
                    && requestStream.EnableDelayedAccept(this.httpOutput, closeOnReceivedEof))
                {
                    return false;
                }
            }

            return true;
        }
            void CompleteChannelModelIntegrationHandlerTask(Message replyMessage)
            {
                if (this.channelModelIntegrationHandlerTask != null)
                {
                    // If Service Model (or service instance) sent us null then we create a 202 HTTP response
                    HttpResponseMessage httpResponseMessage = null;
                    this.httpOutput = this.GetHttpOutput(replyMessage);

                    if (replyMessage != null)
                    {
                        httpResponseMessage = this.CreateHttpResponseMessage(replyMessage);
                    }
                    else
                    {
                        httpResponseMessage = new HttpResponseMessage(HttpStatusCode.Accepted);
                    }

                    Fx.Assert(httpResponseMessage != null, "httpResponse should not be null.");
                    if (httpResponseMessage.RequestMessage == null)
                    {
                        httpResponseMessage.RequestMessage = this.httpRequestMessage;
                        Fx.Assert(httpResponseMessage.RequestMessage != null, "httpResponseMessage.RequestMessage should never be null.");

                        if (replyMessage != null)
                        {
                            httpResponseMessage.CopyPropertiesFromMessage(replyMessage);
                        }
                    }

                    HttpChannelUtilities.EnsureHttpResponseMessageContentNotNull(httpResponseMessage);

                    this.cancellationTokenSource.CancelAfter(TimeoutHelper.ToMilliseconds(this.defaultSendTimeout));
                    this.channelModelIntegrationHandlerTask.TrySetResult(httpResponseMessage);
                }

                this.TraceProcessResponseStop();
            }
 private bool PrepareReply(ref Message message)
 {
     if (message == null)
     {
         message = this.CreateAckMessage(HttpStatusCode.Accepted, string.Empty);
     }
     if (!this.listener.ManualAddressing)
     {
         if (message.Version.Addressing != AddressingVersion.WSAddressingAugust2004)
         {
             if ((message.Version.Addressing != AddressingVersion.WSAddressing10) && (message.Version.Addressing != AddressingVersion.None))
             {
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("AddressingVersionNotSupported", new object[] { message.Version.Addressing })));
             }
             if ((message.Headers.To != null) && ((this.listener.AnonymousUriPrefixMatcher == null) || !this.listener.AnonymousUriPrefixMatcher.IsAnonymousUri(message.Headers.To)))
             {
                 message.Headers.To = null;
             }
         }
         else if (((message.Headers.To == null) || (this.listener.AnonymousUriPrefixMatcher == null)) || !this.listener.AnonymousUriPrefixMatcher.IsAnonymousUri(message.Headers.To))
         {
             message.Headers.To = message.Version.Addressing.AnonymousUri;
         }
     }
     message.Properties.AllowOutputBatching = false;
     this.httpOutput = this.GetHttpOutput(message);
     HttpDelayedAcceptStream inputStream = this.HttpInput.InputStream as HttpDelayedAcceptStream;
     if (((inputStream != null) && TransferModeHelper.IsRequestStreamed(this.listener.TransferMode)) && inputStream.EnableDelayedAccept(this.httpOutput))
     {
         return false;
     }
     return true;
 }