protected override void OnOpened()
        {
            base.OnOpened();

            if (Thread.CurrentThread.IsThreadPoolThread)
            {
                try
                {
                    _ = StartReceivingAsync();
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }

                    ReliableSession.OnUnknownException(e);
                }
            }
            else
            {
                ActionItem.Schedule(new Func <object, Task>(StartReceivingAsync), this);
            }
        }
Esempio n. 2
0
 public void InitializeFrom(ReliableSession reliableSession)
 {
     if (reliableSession == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reliableSession");
     }
     this.Ordered           = reliableSession.Ordered;
     this.InactivityTimeout = reliableSession.InactivityTimeout;
 }
Esempio n. 3
0
 public void ApplyConfiguration(ReliableSession reliableSession)
 {
     if (reliableSession == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reliableSession");
     }
     reliableSession.Ordered           = this.Ordered;
     reliableSession.InactivityTimeout = this.InactivityTimeout;
 }
Esempio n. 4
0
        static void Main(string[] args)
        {
            // <Snippet1>
            // <Snippet2>
            // Create a new reliable session object
            ReliableSessionBindingElement bindingElement = new ReliableSessionBindingElement();
            ReliableSession reliableSession = new ReliableSession(bindingElement);

            // Now you can access property values
            Console.WriteLine("Ordered: {0}", reliableSession.Ordered);
            Console.WriteLine("InactivityTimeout: {0}", reliableSession.InactivityTimeout);
            // </Snippet2>
            reliableSession.Ordered = false;
            Console.WriteLine("The new value for the Ordered property is: {0}", reliableSession.Ordered);
            // </Snippet1>
        }
        protected override void OnApplyConfiguration(Binding binding)
        {
            var b = (WSHttpBindingBase)binding;

            b.BypassProxyOnLocal     = BypassProxyOnLocal;
            b.HostNameComparisonMode = HostNameComparisonMode;
            b.MaxBufferPoolSize      = MaxBufferPoolSize;
            b.MaxReceivedMessageSize = MaxReceivedMessageSize;
            b.MessageEncoding        = MessageEncoding;
            b.ProxyAddress           = ProxyAddress;
            b.ReaderQuotas           = ReaderQuotas.Create();
            ReliableSession.ApplyConfiguration(b.ReliableSession);
            b.TextEncoding       = TextEncoding;
            b.TransactionFlow    = TransactionFlow;
            b.UseDefaultWebProxy = UseDefaultWebProxy;
        }
        private async Task StartReceivingAsync()
        {
            try
            {
                while (true)
                {
                    (bool success, RequestContext context) = await Binder.TryReceiveAsync(TimeSpan.MaxValue);

                    if (success)
                    {
                        if (context != null)
                        {
                            using (context)
                            {
                                Message requestMessage = context.RequestMessage;
                                await ProcessMessageAsync(requestMessage);

                                context.Close(DefaultCloseTimeout);
                            }
                        }
                        else
                        {
                            if (!Connection.Closed && (Binder.State == CommunicationState.Opened))
                            {
                                Exception e = new CommunicationException(SR.EarlySecurityClose);
                                ReliableSession.OnLocalFault(e, (Message)null, null);
                            }

                            // Null context means channel is closing
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }

                ReliableSession.OnUnknownException(e);
            }
        }
        private void ProcessCloseOrTerminateReply(bool close, Message reply)
        {
            if (reply == null)
            {
                // In the close case, the requestor is configured to throw TimeoutException instead of returning null.
                // In the terminate case, this value can be null, but the caller should not call this method.
                throw Fx.AssertAndThrow("Argument reply cannot be null.");
            }

            ReliableRequestor requestor = close ? _closeRequestor : _terminateRequestor;
            WsrmMessageInfo   info      = requestor.GetInfo();

            // Some other thread has verified and cleaned up the reply, no more work to do.
            if (info != null)
            {
                return;
            }

            try
            {
                info = WsrmMessageInfo.Get(Settings.MessageVersion, Settings.ReliableMessagingVersion,
                                           _binder.Channel, _binder.GetInnerSession(), reply);
                ReliableSession.ProcessInfo(info, null, true);
                ReliableSession.VerifyDuplexProtocolElements(info, null, true);

                WsrmFault fault = close
                    ? WsrmUtilities.ValidateCloseSequenceResponse(_session, requestor.MessageId, info,
                                                                  Connection.Last)
                    : WsrmUtilities.ValidateTerminateSequenceResponse(_session, requestor.MessageId, info,
                                                                      Connection.Last);

                if (fault != null)
                {
                    ReliableSession.OnLocalFault(null, fault, null);
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(fault.CreateException());
                }
            }
            finally
            {
                reply.Close();
            }
        }
        protected async Task ProcessMessageAsync(Message message)
        {
            bool            closeMessage = true;
            WsrmMessageInfo messageInfo  = WsrmMessageInfo.Get(Settings.MessageVersion,
                                                               Settings.ReliableMessagingVersion, _binder.Channel, _binder.GetInnerSession(), message);
            bool wsrm11 = Settings.ReliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11;

            try
            {
                if (!_session.ProcessInfo(messageInfo, null))
                {
                    closeMessage = false;
                    return;
                }

                if (!ReliableSession.VerifySimplexProtocolElements(messageInfo, null))
                {
                    closeMessage = false;
                    return;
                }

                bool final = false;

                if (messageInfo.AcknowledgementInfo != null)
                {
                    final = wsrm11 && messageInfo.AcknowledgementInfo.Final;
                    int bufferRemaining = -1;

                    if (Settings.FlowControlEnabled)
                    {
                        bufferRemaining = messageInfo.AcknowledgementInfo.BufferRemaining;
                    }

                    Connection.ProcessTransferred(messageInfo.AcknowledgementInfo.Ranges, bufferRemaining);
                }

                if (wsrm11)
                {
                    WsrmFault fault = null;

                    if (messageInfo.TerminateSequenceResponseInfo != null)
                    {
                        fault = WsrmUtilities.ValidateTerminateSequenceResponse(_session,
                                                                                _terminateRequestor.MessageId, messageInfo, Connection.Last);

                        if (fault == null)
                        {
                            fault = ProcessRequestorResponse(_terminateRequestor, WsrmFeb2005Strings.TerminateSequence, messageInfo);
                        }
                    }
                    else if (messageInfo.CloseSequenceResponseInfo != null)
                    {
                        fault = WsrmUtilities.ValidateCloseSequenceResponse(_session,
                                                                            _closeRequestor.MessageId, messageInfo, Connection.Last);

                        if (fault == null)
                        {
                            fault = ProcessRequestorResponse(_closeRequestor, Wsrm11Strings.CloseSequence, messageInfo);
                        }
                    }
                    else if (messageInfo.TerminateSequenceInfo != null)
                    {
                        if (!WsrmUtilities.ValidateWsrmRequest(_session, messageInfo.TerminateSequenceInfo, _binder, null))
                        {
                            return;
                        }

                        WsrmAcknowledgmentInfo ackInfo = messageInfo.AcknowledgementInfo;
                        fault = WsrmUtilities.ValidateFinalAckExists(_session, ackInfo);

                        if ((fault == null) && !Connection.IsFinalAckConsistent(ackInfo.Ranges))
                        {
                            fault = new InvalidAcknowledgementFault(_session.OutputID, ackInfo.Ranges);
                        }

                        if (fault == null)
                        {
                            Message response = WsrmUtilities.CreateTerminateResponseMessage(
                                Settings.MessageVersion,
                                messageInfo.TerminateSequenceInfo.MessageId,
                                _session.OutputID);

                            try
                            {
                                await OnConnectionSendAsync(response, DefaultSendTimeout, false, true);
                            }
                            finally
                            {
                                response.Close();
                            }

                            _session.OnRemoteFault(new ProtocolException(SR.UnsupportedTerminateSequenceExceptionString));
                            return;
                        }
                    }
                    else if (final)
                    {
                        if (_closeRequestor == null)
                        {
                            string exceptionString = SR.UnsupportedCloseExceptionString;
                            string faultString     = SR.SequenceTerminatedUnsupportedClose;

                            fault = SequenceTerminatedFault.CreateProtocolFault(_session.OutputID, faultString,
                                                                                exceptionString);
                        }
                        else
                        {
                            fault = WsrmUtilities.ValidateFinalAck(_session, messageInfo, Connection.Last);

                            if (fault == null)
                            {
                                _closeRequestor.SetInfo(messageInfo);
                            }
                        }
                    }
                    else if (messageInfo.WsrmHeaderFault != null)
                    {
                        if (!(messageInfo.WsrmHeaderFault is UnknownSequenceFault))
                        {
                            throw Fx.AssertAndThrow("Fault must be UnknownSequence fault.");
                        }

                        if (_terminateRequestor == null)
                        {
                            throw Fx.AssertAndThrow("In wsrm11, if we start getting UnknownSequence, terminateRequestor cannot be null.");
                        }

                        _terminateRequestor.SetInfo(messageInfo);
                    }

                    if (fault != null)
                    {
                        _session.OnLocalFault(fault.CreateException(), fault, null);
                        return;
                    }
                }

                _session.OnRemoteActivity(Connection.Strategy.QuotaRemaining == 0);
            }
            finally
            {
                if (closeMessage)
                {
                    messageInfo.Message.Close();
                }
            }
        }
 private void OnComponentException(Exception exception)
 {
     ReliableSession.OnUnknownException(exception);
 }
Esempio n. 10
0
        // from http://blogs.msdn.com/drnick/archive/2006/07/19/670789.aspx
        static void WSDualHttpMain()
        {
            // <Snippet1>
            WSDualHttpBinding binding = new WSDualHttpBinding();
            // </Snippet1>


            // <Snippet2>
            string            configName    = "string";
            WSDualHttpBinding bindingString = new WSDualHttpBinding(configName);
            // </Snippet2>

            // <Snippet3>
            WSDualHttpBinding bindingSecurityMode =
                new WSDualHttpBinding(WSDualHttpSecurityMode.Message);
            // </Snippet3>


            /*            String clientBaseAddress = "http://localhost:8080/Discovery/" + Guid.NewGuid().ToString();
             *          Uri clientBaseAddressUri = new Uri(clientBaseAddress);
             *          WSDualHttpBinding bindingClientBaseAddress =
             *              new WSDualHttpBinding(clientBaseAddressUri);
             */
            // <Snippet8>
            WSDualHttpBinding dualBinding = new WSDualHttpBinding();
            EndpointAddress   endptadr    = new EndpointAddress("http://localhost:12000/DuplexTestUsingCode/Server");

            dualBinding.ClientBaseAddress = new Uri("http://localhost:8000/DuplexTestUsingCode/Client/");

            // </Snippet8>

            // <Snippet9>
            // Set to StrongWildCard
            binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
            // </Snippet9>

            // <Snippet10>
            binding.MaxBufferPoolSize = 900000;
            // </Snippet10>

            // <Snippet11>
            binding.MessageEncoding = WSMessageEncoding.Mtom;
            // </Snippet11>

            // <Snippet12>
            string proxyAddressString  = "http://localhost:5049";
            Uri    proxyBaseAddressUri = new Uri(proxyAddressString);

            binding.ProxyAddress = proxyBaseAddressUri;
            // </Snippet12>

            // <Snippet13>
            XmlDictionaryReaderQuotas readerQuotas =
                binding.ReaderQuotas;
            // </Snippet13>

            // <Snippet14>
            ReliableSession reliableSession =
                binding.ReliableSession;
            // </Snippet14>

            // <Snippet15>
            string scheme = binding.Scheme;
            // </Snippet15>

            // <Snippet16>
            WSDualHttpSecurity security = binding.Security;
            // </Snippet16>

            // <Snippet17>
            Encoding bindingEncoding = binding.TextEncoding;

            // </Snippet17>

            // <Snippet18>
            binding.TransactionFlow = true;
            // </Snippet18>

            // <Snippet19>
            binding.UseDefaultWebProxy = true;
            // </Snippet19>

            // <Snippet20>
            BindingElementCollection bec = binding.CreateBindingElements();
            // </Snippet20>

            // <Snippet21>
            EnvelopeVersion envelopeversion = binding.EnvelopeVersion;
            // </Snippet21>

            // <Snippet22>
            long maxReceivedMessageSize = binding.MaxReceivedMessageSize;

            // </Snippet22>



            binding.Security.Mode = WSDualHttpSecurityMode.None;
            //<snippet30>
            WSDualHttpBinding binding3 = new WSDualHttpBinding();

            binding3.Security.Mode = WSDualHttpSecurityMode.None;
            binding3.Security.Message.AlgorithmSuite = SecurityAlgorithmSuite.Basic256;
            binding3.MessageEncoding = WSMessageEncoding.Mtom;
            //</snippet30>

            // <Snippet6>
            WSDualHttpBinding BypassProxyOnLocalBinding =
                new WSDualHttpBinding();

            BypassProxyOnLocalBinding.BypassProxyOnLocal = true;
            // <//Snippet6>

            //AnalyzeBindings(binding1, binding2, binding3);
        }
Esempio n. 11
0
        // Methods

        public void ApplyConfiguration(ReliableSession reliableSession)
        {
            reliableSession.InactivityTimeout = InactivityTimeout;
            reliableSession.Ordered           = Ordered;
        }
        // Methods

        public void ApplyConfiguration(ReliableSession s)
        {
            s.InactivityTimeout = InactivityTimeout;
            s.Ordered           = Ordered;
        }