private bool HandleWriteUpgradeResponseComplete(IAsyncResult result) { bool flag; this.channel.Connection.EndWrite(result); Microsoft.ServiceBus.Channels.IConnection connection = this.channel.Connection; if (this.channel.size > 0) { connection = new Microsoft.ServiceBus.Channels.PreReadConnection(connection, this.channel.connectionBuffer, this.channel.offset, this.channel.size); } if (Microsoft.ServiceBus.Channels.ServerSessionPreambleConnectionReader.ServerFramingDuplexSessionChannel.OpenAsyncResult.onUpgradeConnection == null) { Microsoft.ServiceBus.Channels.ServerSessionPreambleConnectionReader.ServerFramingDuplexSessionChannel.OpenAsyncResult.onUpgradeConnection = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ThunkAsyncCallback(new AsyncCallback(Microsoft.ServiceBus.Channels.ServerSessionPreambleConnectionReader.ServerFramingDuplexSessionChannel.OpenAsyncResult.OnUpgradeConnection)); } try { IAsyncResult asyncResult = Microsoft.ServiceBus.Channels.InitialServerConnectionReader.BeginUpgradeConnection(connection, this.channel.upgradeAcceptor, this.channel, Microsoft.ServiceBus.Channels.ServerSessionPreambleConnectionReader.ServerFramingDuplexSessionChannel.OpenAsyncResult.onUpgradeConnection, this); flag = (asyncResult.CompletedSynchronously ? this.HandleUpgradeConnectionComplete(asyncResult) : false); } catch (Exception exception1) { Exception exception = exception1; if (Fx.IsFatal(exception)) { throw; } this.channel.WriteAuditFailure(this.channel.upgradeAcceptor as StreamSecurityUpgradeAcceptor, exception); throw; } return(flag); }
public Microsoft.ServiceBus.Channels.IConnection GetRawConnection() { Microsoft.ServiceBus.Channels.IConnection preReadConnection = null; if (this.rawConnection != null) { preReadConnection = this.rawConnection; this.rawConnection = null; if (this.size > 0) { Microsoft.ServiceBus.Channels.PreReadConnection preReadConnection1 = preReadConnection as Microsoft.ServiceBus.Channels.PreReadConnection; if (preReadConnection1 == null) { preReadConnection = new Microsoft.ServiceBus.Channels.PreReadConnection(preReadConnection, this.buffer, this.offset, this.size); } else { preReadConnection1.AddPreReadData(this.buffer, this.offset, this.size); } } } return(preReadConnection); }
public Message Receive(TimeSpan timeout) { Message message; ServiceModelActivity serviceModelActivity; SecurityMessageProperty securityMessageProperty; byte[] numArray = this.transportSettings.BufferManager.TakeBuffer(this.connection.AsyncReadBufferSize); if (this.size > 0) { Buffer.BlockCopy(this.connection.AsyncReadBuffer, this.offset, numArray, this.offset, this.size); } try { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); while (!this.DecodeBytes(numArray, ref this.offset, ref this.size, ref this.isAtEof)) { if (!this.isAtEof) { if (this.size != 0) { continue; } this.offset = 0; this.size = this.connection.Read(numArray, 0, (int)numArray.Length, timeoutHelper.RemainingTime()); if (this.size != 0) { continue; } this.DoneReceiving(true, timeoutHelper.RemainingTime()); message = null; return(message); } else { this.DoneReceiving(true, timeoutHelper.RemainingTime()); message = null; return(message); } } Microsoft.ServiceBus.Channels.IConnection preReadConnection = this.connection; if (this.size > 0) { byte[] numArray1 = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.Utility.AllocateByteArray(this.size); Buffer.BlockCopy(numArray, this.offset, numArray1, 0, this.size); preReadConnection = new Microsoft.ServiceBus.Channels.PreReadConnection(preReadConnection, numArray1); } Stream singletonInputConnectionStream = new Microsoft.ServiceBus.Channels.SingletonConnectionReader.SingletonInputConnectionStream(this, preReadConnection, this.transportSettings); this.inputStream = new Microsoft.ServiceBus.Channels.MaxMessageSizeStream(singletonInputConnectionStream, this.transportSettings.MaxReceivedMessageSize); if (Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldUseActivity) { serviceModelActivity = ServiceModelActivity.CreateBoundedActivity(true); } else { serviceModelActivity = null; } using (serviceModelActivity) { Message message1 = null; try { message1 = this.transportSettings.MessageEncoderFactory.Encoder.ReadMessage(this.inputStream, this.transportSettings.MaxBufferSize, this.ContentType); } catch (XmlException xmlException1) { XmlException xmlException = xmlException1; throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(Microsoft.ServiceBus.SR.GetString(Resources.MessageXmlProtocolError, new object[0]), xmlException)); } message1.Properties.Via = this.via; MessageProperties properties = message1.Properties; if (this.security != null) { securityMessageProperty = (SecurityMessageProperty)this.security.CreateCopy(); } else { securityMessageProperty = null; } properties.Security = securityMessageProperty; this.PrepareMessage(message1); message = message1; } } finally { this.transportSettings.BufferManager.ReturnBuffer(numArray); } return(message); }
protected override void OnOpen(TimeSpan timeout) { bool flag = false; try { Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout); this.ValidateContentType(ref timeoutHelper); while (true) { if (this.size == 0) { this.offset = 0; this.size = base.Connection.Read(this.connectionBuffer, 0, (int)this.connectionBuffer.Length, timeoutHelper.RemainingTime()); if (this.size == 0) { break; } } do { this.DecodeBytes(); switch (this.decoder.CurrentState) { case Microsoft.ServiceBus.Channels.ServerSessionDecoder.State.UpgradeRequest: { this.ProcessUpgradeRequest(ref timeoutHelper); base.Connection.Write(Microsoft.ServiceBus.Channels.ServerSessionEncoder.UpgradeResponseBytes, 0, (int)Microsoft.ServiceBus.Channels.ServerSessionEncoder.UpgradeResponseBytes.Length, true, timeoutHelper.RemainingTime()); Microsoft.ServiceBus.Channels.IConnection connection = base.Connection; if (this.size > 0) { connection = new Microsoft.ServiceBus.Channels.PreReadConnection(connection, this.connectionBuffer, this.offset, this.size); } try { base.Connection = Microsoft.ServiceBus.Channels.InitialServerConnectionReader.UpgradeConnection(connection, this.upgradeAcceptor, this); this.connectionBuffer = base.Connection.AsyncReadBuffer; continue; } catch (Exception exception1) { Exception exception = exception1; if (Fx.IsFatal(exception)) { throw; } this.WriteAuditFailure(this.upgradeAcceptor as StreamSecurityUpgradeAcceptor, exception); throw; } break; } case Microsoft.ServiceBus.Channels.ServerSessionDecoder.State.Start: { this.SetupSecurityIfNecessary(); base.Connection.Write(Microsoft.ServiceBus.Channels.ServerSessionEncoder.AckResponseBytes, 0, (int)Microsoft.ServiceBus.Channels.ServerSessionEncoder.AckResponseBytes.Length, true, timeoutHelper.RemainingTime()); this.SetupSessionReader(); flag = true; return; } default: { continue; } } }while (this.size != 0); } throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(this.decoder.CreatePrematureEOFException()); } finally { if (!flag) { base.Connection.Abort(); } } }
public Microsoft.ServiceBus.Channels.IConnection CompletePreamble(TimeSpan timeout) { Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout); if (!this.transportSettings.MessageEncoderFactory.Encoder.IsContentTypeSupported(this.decoder.ContentType)) { this.SendFault("http://schemas.microsoft.com/ws/2006/05/framing/faults/ContentTypeInvalid", ref timeoutHelper); ExceptionUtility exceptionUtility = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility; string contentTypeMismatch = Resources.ContentTypeMismatch; object[] contentType = new object[] { this.decoder.ContentType, this.transportSettings.MessageEncoderFactory.Encoder.ContentType }; throw exceptionUtility.ThrowHelperError(new ProtocolException(Microsoft.ServiceBus.SR.GetString(contentTypeMismatch, contentType))); } StreamUpgradeAcceptor streamUpgradeAcceptor = null; StreamUpgradeProvider upgrade = this.transportSettings.Upgrade; if (upgrade != null) { streamUpgradeAcceptor = upgrade.CreateUpgradeAcceptor(); } Microsoft.ServiceBus.Channels.IConnection connection = base.Connection; while (true) { if (this.size == 0) { this.offset = 0; this.size = connection.Read(this.connectionBuffer, 0, (int)this.connectionBuffer.Length, timeoutHelper.RemainingTime()); if (this.size == 0) { break; } } do { int num = this.decoder.Decode(this.connectionBuffer, this.offset, this.size); if (num > 0) { Microsoft.ServiceBus.Channels.ServerSingletonPreambleConnectionReader serverSingletonPreambleConnectionReader = this; serverSingletonPreambleConnectionReader.offset = serverSingletonPreambleConnectionReader.offset + num; Microsoft.ServiceBus.Channels.ServerSingletonPreambleConnectionReader serverSingletonPreambleConnectionReader1 = this; serverSingletonPreambleConnectionReader1.size = serverSingletonPreambleConnectionReader1.size - num; } switch (this.decoder.CurrentState) { case Microsoft.ServiceBus.Channels.ServerSingletonDecoder.State.UpgradeRequest: { if (streamUpgradeAcceptor == null) { this.SendFault("http://schemas.microsoft.com/ws/2006/05/framing/faults/UpgradeInvalid", ref timeoutHelper); ExceptionUtility exceptionUtility1 = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility; string upgradeRequestToNonupgradableService = Resources.UpgradeRequestToNonupgradableService; object[] objArray = new object[] { this.decoder.Upgrade }; throw exceptionUtility1.ThrowHelperError(new ProtocolException(Microsoft.ServiceBus.SR.GetString(upgradeRequestToNonupgradableService, objArray))); } if (!streamUpgradeAcceptor.CanUpgrade(this.decoder.Upgrade)) { this.SendFault("http://schemas.microsoft.com/ws/2006/05/framing/faults/UpgradeInvalid", ref timeoutHelper); ExceptionUtility exceptionUtility2 = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility; string upgradeProtocolNotSupported = Resources.UpgradeProtocolNotSupported; object[] upgrade1 = new object[] { this.decoder.Upgrade }; throw exceptionUtility2.ThrowHelperError(new ProtocolException(Microsoft.ServiceBus.SR.GetString(upgradeProtocolNotSupported, upgrade1))); } connection.Write(Microsoft.ServiceBus.Channels.ServerSingletonEncoder.UpgradeResponseBytes, 0, (int)Microsoft.ServiceBus.Channels.ServerSingletonEncoder.UpgradeResponseBytes.Length, true, timeoutHelper.RemainingTime()); Microsoft.ServiceBus.Channels.IConnection preReadConnection = connection; if (this.size > 0) { preReadConnection = new Microsoft.ServiceBus.Channels.PreReadConnection(preReadConnection, this.connectionBuffer, this.offset, this.size); } try { connection = Microsoft.ServiceBus.Channels.InitialServerConnectionReader.UpgradeConnection(preReadConnection, streamUpgradeAcceptor, this.transportSettings); this.connectionBuffer = connection.AsyncReadBuffer; continue; } catch (Exception exception1) { Exception exception = exception1; if (Fx.IsFatal(exception)) { throw; } this.WriteAuditFailure(streamUpgradeAcceptor as StreamSecurityUpgradeAcceptor, exception); throw; } break; } case Microsoft.ServiceBus.Channels.ServerSingletonDecoder.State.Start: { this.SetupSecurityIfNecessary(streamUpgradeAcceptor); connection.Write(Microsoft.ServiceBus.Channels.ServerSessionEncoder.AckResponseBytes, 0, (int)Microsoft.ServiceBus.Channels.ServerSessionEncoder.AckResponseBytes.Length, true, timeoutHelper.RemainingTime()); return(connection); } default: { continue; } } }while (this.size != 0); } throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(this.decoder.CreatePrematureEOFException()); }