Example #1
0
 private Microsoft.ServiceBus.Channels.IConnection SendPreamble(Microsoft.ServiceBus.Channels.IConnection connection, ArraySegment <byte> preamble, ref Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper)
 {
     this.decoder = new Microsoft.ServiceBus.Channels.ClientDuplexDecoder((long)0);
     byte[] numArray = new byte[1];
     connection.Write(preamble.Array, preamble.Offset, preamble.Count, true, timeoutHelper.RemainingTime());
     if (this.upgrade != null)
     {
         StreamUpgradeInitiator streamUpgradeInitiator = this.upgrade.CreateUpgradeInitiator(this.RemoteAddress, this.Via);
         Type     type     = streamUpgradeInitiator.GetType();
         object[] objArray = new object[] { timeoutHelper.RemainingTime() };
         InvokeHelper.InvokeInstanceMethod(type, streamUpgradeInitiator, "Open", objArray);
         if (!Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.InitiateUpgrade(streamUpgradeInitiator, ref connection, this.decoder, this, ref timeoutHelper))
         {
             Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.DecodeFramingFault(this.decoder, connection, this.Via, base.MessageEncoder.ContentType, ref timeoutHelper);
         }
         this.SetRemoteSecurity(streamUpgradeInitiator);
         Type     type1     = streamUpgradeInitiator.GetType();
         object[] objArray1 = new object[] { timeoutHelper.RemainingTime() };
         InvokeHelper.InvokeInstanceMethod(type1, streamUpgradeInitiator, "Close", objArray1);
         connection.Write(Microsoft.ServiceBus.Channels.SessionEncoder.PreambleEndBytes, 0, (int)Microsoft.ServiceBus.Channels.SessionEncoder.PreambleEndBytes.Length, true, timeoutHelper.RemainingTime());
     }
     if (!Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.ValidatePreambleResponse(numArray, connection.Read(numArray, 0, (int)numArray.Length, timeoutHelper.RemainingTime()), this.decoder, this.Via))
     {
         Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.DecodeFramingFault(this.decoder, connection, this.Via, base.MessageEncoder.ContentType, ref timeoutHelper);
     }
     return(connection);
 }
Example #2
0
            private bool HandleInitiatorOpen(IAsyncResult result)
            {
                Type type = this.upgradeInitiator.GetType();
                StreamUpgradeInitiator streamUpgradeInitiator = this.upgradeInitiator;

                object[] objArray = new object[] { result };
                InvokeHelper.InvokeInstanceMethod(type, streamUpgradeInitiator, "EndOpen", objArray);
                if (Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.SendPreambleAsyncResult.onUpgrade == null)
                {
                    Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.SendPreambleAsyncResult.onUpgrade = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ThunkAsyncCallback(new AsyncCallback(Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.SendPreambleAsyncResult.OnUpgrade));
                }
                IAsyncResult asyncResult = Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.BeginInitiateUpgrade(this.channel, this.channel.RemoteAddress, this.connection, this.channel.decoder, this.upgradeInitiator, this.channel.MessageEncoder.ContentType, this.timeoutHelper, Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.SendPreambleAsyncResult.onUpgrade, this);

                if (!asyncResult.CompletedSynchronously)
                {
                    return(false);
                }
                return(this.HandleUpgrade(asyncResult));
            }
Example #3
0
            private bool HandleUpgrade(IAsyncResult result)
            {
                this.connection = Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.EndInitiateUpgrade(result);
                this.channel.SetRemoteSecurity(this.upgradeInitiator);
                if (Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.SendPreambleAsyncResult.onUpgradeInitiatorClose == null)
                {
                    Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.SendPreambleAsyncResult.onUpgradeInitiatorClose = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ThunkAsyncCallback(new AsyncCallback(Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.SendPreambleAsyncResult.OnUpgradeInitiatorClose));
                }
                Type type = this.upgradeInitiator.GetType();
                StreamUpgradeInitiator streamUpgradeInitiator = this.upgradeInitiator;

                object[]     objArray    = new object[] { this.timeoutHelper.RemainingTime(), Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.SendPreambleAsyncResult.onUpgradeInitiatorClose, this };
                IAsyncResult asyncResult = InvokeHelper.InvokeInstanceMethod(type, streamUpgradeInitiator, "BeginClose", objArray) as IAsyncResult;

                if (!asyncResult.CompletedSynchronously)
                {
                    return(false);
                }
                return(this.HandleInitiatorClose(asyncResult));
            }
Example #4
0
            private bool HandleInitiatorClose(IAsyncResult result)
            {
                Type type = this.upgradeInitiator.GetType();
                StreamUpgradeInitiator streamUpgradeInitiator = this.upgradeInitiator;

                object[] objArray = new object[] { result };
                InvokeHelper.InvokeInstanceMethod(type, streamUpgradeInitiator, "EndClose", objArray);
                this.upgradeInitiator = null;
                if (Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.SendPreambleAsyncResult.onWritePreambleEnd == null)
                {
                    Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.SendPreambleAsyncResult.onWritePreambleEnd = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ThunkAsyncCallback(new AsyncCallback(Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.SendPreambleAsyncResult.OnWritePreambleEnd));
                }
                IAsyncResult asyncResult = this.connection.BeginWrite(Microsoft.ServiceBus.Channels.SessionEncoder.PreambleEndBytes, 0, (int)Microsoft.ServiceBus.Channels.SessionEncoder.PreambleEndBytes.Length, true, this.timeoutHelper.RemainingTime(), Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.SendPreambleAsyncResult.onWritePreambleEnd, this);

                if (!asyncResult.CompletedSynchronously)
                {
                    return(false);
                }
                this.connection.EndWrite(asyncResult);
                return(this.ReadAck());
            }
Example #5
0
            private bool HandleWritePreamble(IAsyncResult result)
            {
                this.connection.EndWrite(result);
                if (this.channel.upgrade == null)
                {
                    return(this.ReadAck());
                }
                this.upgradeInitiator = this.channel.upgrade.CreateUpgradeInitiator(this.channel.RemoteAddress, this.channel.Via);
                if (Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.SendPreambleAsyncResult.onUpgradeInitiatorOpen == null)
                {
                    Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.SendPreambleAsyncResult.onUpgradeInitiatorOpen = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ThunkAsyncCallback(new AsyncCallback(Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.SendPreambleAsyncResult.OnUpgradeInitiatorOpen));
                }
                Type type = this.upgradeInitiator.GetType();
                StreamUpgradeInitiator streamUpgradeInitiator = this.upgradeInitiator;

                object[]     objArray    = new object[] { this.timeoutHelper.RemainingTime(), Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.SendPreambleAsyncResult.onUpgradeInitiatorOpen, this };
                IAsyncResult asyncResult = InvokeHelper.InvokeInstanceMethod(type, streamUpgradeInitiator, "BeginOpen", objArray) as IAsyncResult;

                if (!asyncResult.CompletedSynchronously)
                {
                    return(false);
                }
                return(this.HandleInitiatorOpen(asyncResult));
            }
Example #6
0
        protected TransportChannelListener(TransportBindingElement bindingElement, BindingContext context, System.ServiceModel.Channels.MessageEncoderFactory defaultMessageEncoderFactory, HostNameComparisonMode hostNameComparisonMode) : base(context.Binding)
        {
            Microsoft.ServiceBus.Channels.HostNameComparisonModeHelper.Validate(hostNameComparisonMode);
            this.hostNameComparisonMode = hostNameComparisonMode;
            this.manualAddressing       = bindingElement.ManualAddressing;
            this.maxBufferPoolSize      = bindingElement.MaxBufferPoolSize;
            this.maxReceivedMessageSize = bindingElement.MaxReceivedMessageSize;
            Collection <MessageEncodingBindingElement> messageEncodingBindingElements = context.BindingParameters.FindAll <MessageEncodingBindingElement>();

            if (messageEncodingBindingElements.Count > 1)
            {
                throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(Microsoft.ServiceBus.SR.GetString(Resources.MultipleMebesInParameters, new object[0])));
            }
            if (messageEncodingBindingElements.Count != 1)
            {
                this.messageEncoderFactory = defaultMessageEncoderFactory;
            }
            else
            {
                this.messageEncoderFactory = messageEncodingBindingElements[0].CreateMessageEncoderFactory();
                context.BindingParameters.Remove <MessageEncodingBindingElement>();
            }
            if (this.messageEncoderFactory == null)
            {
                this.messageVersion = System.ServiceModel.Channels.MessageVersion.None;
            }
            else
            {
                this.messageVersion = this.messageEncoderFactory.MessageVersion;
            }
            ServiceSecurityAuditBehavior serviceSecurityAuditBehavior = context.BindingParameters.Find <ServiceSecurityAuditBehavior>();

            if (serviceSecurityAuditBehavior == null)
            {
                this.auditBehavior = new ServiceSecurityAuditBehavior();
            }
            else
            {
                this.auditBehavior = (ServiceSecurityAuditBehavior)InvokeHelper.InvokeInstanceMethod(typeof(ServiceSecurityAuditBehavior), serviceSecurityAuditBehavior, "Clone", new object[0]);
            }
            if (context.ListenUriMode == ListenUriMode.Unique && context.ListenUriBaseAddress == null)
            {
                UriBuilder uriBuilder = new UriBuilder(this.Scheme, Microsoft.ServiceBus.Channels.DnsCache.MachineName)
                {
                    Path = this.GeneratedAddressPrefix
                };
                context.ListenUriBaseAddress = uriBuilder.Uri;
            }
            Microsoft.ServiceBus.Channels.UriSchemeKeyedCollection.ValidateBaseAddress(context.ListenUriBaseAddress, "baseAddress");
            if (context.ListenUriBaseAddress.Scheme != this.Scheme && !context.ListenUriBaseAddress.Scheme.Equals("sbwss") && string.Compare(context.ListenUriBaseAddress.Scheme, this.Scheme, StringComparison.OrdinalIgnoreCase) != 0)
            {
                ExceptionUtility exceptionUtility = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility;
                string           invalidUriScheme = Resources.InvalidUriScheme;
                object[]         scheme           = new object[] { context.ListenUriBaseAddress.Scheme, this.Scheme };
                throw exceptionUtility.ThrowHelperArgument("context.ListenUriBaseAddress", Microsoft.ServiceBus.SR.GetString(invalidUriScheme, scheme));
            }
            Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.DebugAssert(context.ListenUriRelativeAddress != null, "");
            if (context.ListenUriMode != ListenUriMode.Explicit)
            {
                string listenUriRelativeAddress = context.ListenUriRelativeAddress;
                if (listenUriRelativeAddress.Length > 0 && !listenUriRelativeAddress.EndsWith("/", StringComparison.Ordinal))
                {
                    listenUriRelativeAddress = string.Concat(listenUriRelativeAddress, "/");
                }
                System.Uri listenUriBaseAddress = context.ListenUriBaseAddress;
                Guid       guid = Guid.NewGuid();
                this.SetUri(listenUriBaseAddress, string.Concat(listenUriRelativeAddress, guid.ToString()));
            }
            else
            {
                this.SetUri(context.ListenUriBaseAddress, context.ListenUriRelativeAddress);
            }
            this.transportManagerContainer = new Microsoft.ServiceBus.Channels.TransportManagerContainer(this);
        }