void PrepareRequest(Message message)
        {
            RequestReplyCorrelator.PrepareRequest(message);
            if (this.requiresManualReplyAddressing)
            {
                if (this.localAddress != null)
                {
                    message.Headers.ReplyTo = this.LocalAddress;
                }
                else
                {
                    message.Headers.ReplyTo = EndpointAddress.AnonymousAddress;
                }
            }

            if (this.webHeaderCollection != null && this.webHeaderCollection.Count > 0)
            {
                object prop = null;
                HttpRequestMessageProperty rmp = null;
                if (message.Properties.TryGetValue(HttpRequestMessageProperty.Name, out prop))
                {
                    rmp = prop as HttpRequestMessageProperty;
                }
                else
                {
                    rmp = new HttpRequestMessageProperty();
                    message.Properties.Add(HttpRequestMessageProperty.Name, rmp);
                }

                if (rmp != null && rmp.Headers != null)
                {
                    rmp.Headers.Add(this.webHeaderCollection);
                }
            }
        }
Exemplo n.º 2
0
 private void PrepareRequest(Message nextMessage, RequestSecurityToken rst)
 {
     if ((rst != null) && !rst.IsReadOnly)
     {
         rst.Message = nextMessage;
     }
     RequestReplyCorrelator.PrepareRequest(nextMessage);
     if (this.RequiresManualReplyAddressing)
     {
         nextMessage.Headers.ReplyTo = EndpointAddress.AnonymousAddress;
     }
 }
 void PrepareRequest(Message nextMessage, RequestSecurityToken rst)
 {
     if (rst != null && !rst.IsReadOnly)
     {
         rst.Message = nextMessage;
     }
     RequestReplyCorrelator.PrepareRequest(nextMessage);
     if (this.RequiresManualReplyAddressing)
     {
         // if we are on HTTP, we need to explicitly add a reply-to header for interop
         nextMessage.Headers.ReplyTo = EndpointAddress.AnonymousAddress;
     }
 }
Exemplo n.º 4
0
        public async Task <Message> RequestAsync(Message message, CancellationToken token)
        {
            RequestReplyCorrelator.PrepareRequest(message);
            AsyncDuplexRequest duplexRequest = new AsyncDuplexRequest(this);

            lock (ThisLock)
            {
                RequestStarting(message, duplexRequest);
            }

            await _channel.SendAsync(message, token);

            return(await duplexRequest.WaitForReplyAsync(token));
        }
Exemplo n.º 5
0
 private void PrepareRequest(Message message)
 {
     RequestReplyCorrelator.PrepareRequest(message);
     if (this.requiresManualReplyAddressing)
     {
         if (this.localAddress != null)
         {
             message.Headers.ReplyTo = this.LocalAddress;
         }
         else
         {
             message.Headers.ReplyTo = EndpointAddress.AnonymousAddress;
         }
     }
 }
        public IAsyncResult BeginRequest(Message message, TimeSpan timeout, AsyncCallback callback, object state)
        {
            IAsyncResult       result2;
            bool               flag    = false;
            AsyncDuplexRequest request = null;

            try
            {
                RequestReplyCorrelator.PrepareRequest(message);
                request = new AsyncDuplexRequest(message, this, timeout, callback, state);
                lock (this.ThisLock)
                {
                    this.RequestStarting(message, request);
                }
                IAsyncResult sendResult = this.channel.BeginSend(message, timeout, Fx.ThunkCallback(new AsyncCallback(this.SendCallback)), request);
                if (sendResult.CompletedSynchronously)
                {
                    request.FinishedSend(sendResult, true);
                }
                this.EnsurePumping();
                flag    = true;
                result2 = request;
            }
            finally
            {
                lock (this.ThisLock)
                {
                    if (flag)
                    {
                        request.EnableCompletion();
                    }
                    else
                    {
                        this.RequestCompleting(request);
                    }
                }
            }
            return(result2);
        }
Exemplo n.º 7
0
        public async Task <Message> RequestAsync(Message message, CancellationToken token)
        {
            AsyncDuplexRequest duplexRequest = null;
            bool optimized = false;

            RequestReplyCorrelator.PrepareRequest(message);

            lock (ThisLock)
            {
                if (!Pumping)
                {
                    optimized       = true;
                    syncPumpEnabled = true;
                }

                if (!optimized)
                {
                    duplexRequest = new AsyncDuplexRequest(this);
                }

                RequestStarting(message, duplexRequest);
            }

            if (optimized)
            {
                UniqueId messageId = message.Headers.MessageId;

                try
                {
                    await channel.SendAsync(message, token);

                    //if (DiagnosticUtility.ShouldUseActivity &&
                    //    ServiceModelActivity.Current != null &&
                    //    ServiceModelActivity.Current.ActivityType == ActivityType.ProcessAction)
                    //{
                    //    ServiceModelActivity.Current.Suspend();
                    //}

                    for (;;)
                    {
                        var result = await channel.TryReceiveAsync(token);

                        if (!result.Success)
                        {
                            // TODO: Derive CancellationToken to attach timeout
                            throw TraceUtility.ThrowHelperError(GetReceiveTimeoutException(TimeSpan.Zero), message);
                        }

                        if (result.Result == null)
                        {
                            AbortRequests();
                            return(null);
                        }

                        if (result.Result.Headers.RelatesTo == messageId)
                        {
                            ThrowIfInvalidReplyIdentity(result.Result);
                            return(result.Result);
                        }
                        else if (!HandleRequestAsReply(result.Result))
                        {
                            // SFx drops a message here
                            //if (DiagnosticUtility.ShouldTraceInformation)
                            //{
                            //    EndpointDispatcher dispatcher = null;
                            //    if (this.ChannelHandler != null && this.ChannelHandler.Channel != null)
                            //    {
                            //        dispatcher = this.ChannelHandler.Channel.EndpointDispatcher;
                            //    }
                            //    TraceUtility.TraceDroppedMessage(reply, dispatcher);
                            //}
                            result.Result.Close();
                        }
                    }
                }
                finally
                {
                    lock (ThisLock)
                    {
                        RequestCompleting(null);
                        syncPumpEnabled = false;
                        if (pending > 0)
                        {
                            EnsurePumping();
                        }
                    }
                }
            }
            else
            {
                await channel.SendAsync(message, token);

                EnsurePumping();
                return(await duplexRequest.WaitForReplyAsync(token));
            }
        }
        public Message Request(Message message, TimeSpan timeout)
        {
            SyncDuplexRequest request = null;
            bool flag = false;

            RequestReplyCorrelator.PrepareRequest(message);
            lock (this.ThisLock)
            {
                if (!this.Pumping)
                {
                    flag = true;
                    this.syncPumpEnabled = true;
                }
                if (!flag)
                {
                    request = new SyncDuplexRequest(this);
                }
                this.RequestStarting(message, request);
            }
            if (flag)
            {
                TimeoutHelper helper    = new TimeoutHelper(timeout);
                UniqueId      messageId = message.Headers.MessageId;
                try
                {
                    this.channel.Send(message, helper.RemainingTime());
                    if ((DiagnosticUtility.ShouldUseActivity && (ServiceModelActivity.Current != null)) && (ServiceModelActivity.Current.ActivityType == ActivityType.ProcessAction))
                    {
                        ServiceModelActivity.Current.Suspend();
                    }
                    while (true)
                    {
                        Message  message2;
                        TimeSpan span = helper.RemainingTime();
                        if (!this.channel.TryReceive(span, out message2))
                        {
                            throw TraceUtility.ThrowHelperError(this.GetReceiveTimeoutException(timeout), message);
                        }
                        if (message2 == null)
                        {
                            this.AbortRequests();
                            return(null);
                        }
                        if (message2.Headers.RelatesTo == messageId)
                        {
                            this.ThrowIfInvalidReplyIdentity(message2);
                            return(message2);
                        }
                        if (!this.HandleRequestAsReply(message2))
                        {
                            if (DiagnosticUtility.ShouldTraceInformation)
                            {
                                EndpointDispatcher endpointDispatcher = null;
                                if ((this.ChannelHandler != null) && (this.ChannelHandler.Channel != null))
                                {
                                    endpointDispatcher = this.ChannelHandler.Channel.EndpointDispatcher;
                                }
                                TraceUtility.TraceDroppedMessage(message2, endpointDispatcher);
                            }
                            message2.Close();
                        }
                    }
                }
                finally
                {
                    lock (this.ThisLock)
                    {
                        this.RequestCompleting(null);
                        this.syncPumpEnabled = false;
                        if (this.pending > 0)
                        {
                            this.EnsurePumping();
                        }
                    }
                }
            }
            TimeoutHelper helper2 = new TimeoutHelper(timeout);

            this.channel.Send(message, helper2.RemainingTime());
            this.EnsurePumping();
            return(request.WaitForReply(helper2.RemainingTime()));
        }