public static void DecodeFramingFault(ClientFramingDecoder decoder, IConnection connection, Uri via, string contentType, ref TimeoutHelper timeoutHelper) { ValidateReadingFaultString(decoder); int offset = 0; byte[] buffer = DiagnosticUtility.Utility.AllocateByteArray(0x100); int size = connection.Read(buffer, offset, buffer.Length, timeoutHelper.RemainingTime()); while (size > 0) { int num3 = decoder.Decode(buffer, offset, size); offset += num3; size -= num3; if (decoder.CurrentState == ClientFramingDecoderState.Fault) { ConnectionUtilities.CloseNoThrow(connection, timeoutHelper.RemainingTime()); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(FaultStringDecoder.GetFaultException(decoder.Fault, via.ToString(), contentType)); } if (decoder.CurrentState != ClientFramingDecoderState.ReadingFaultString) { throw Fx.AssertAndThrow("invalid framing client state machine"); } if (size == 0) { offset = 0; size = connection.Read(buffer, offset, buffer.Length, timeoutHelper.RemainingTime()); } } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(decoder.CreatePrematureEOFException()); }
public static async Task DecodeFramingFaultAsync(ClientFramingDecoder decoder, IConnection connection, Uri via, string contentType, TimeSpan timeout) { var timeoutHelper = new TimeoutHelper(timeout); ValidateReadingFaultString(decoder); var tcs = new TaskCompletionSource <bool>(); var result = connection.BeginRead(0, Math.Min(FaultStringDecoder.FaultSizeQuota, connection.AsyncReadBufferSize), timeoutHelper.RemainingTime(), FramingDuplexSessionChannel.OnIoComplete, tcs); if (result == AsyncCompletionResult.Completed) { tcs.TrySetResult(true); } await tcs.Task; int offset = 0; int size = connection.EndRead(); while (size > 0) { int bytesDecoded = decoder.Decode(connection.AsyncReadBuffer, offset, size); offset += bytesDecoded; size -= bytesDecoded; if (decoder.CurrentState == ClientFramingDecoderState.Fault) { ConnectionUtilities.CloseNoThrow(connection, timeoutHelper.RemainingTime()); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( FaultStringDecoder.GetFaultException(decoder.Fault, via.ToString(), contentType)); } else { if (decoder.CurrentState != ClientFramingDecoderState.ReadingFaultString) { throw new Exception("invalid framing client state machine"); } if (size == 0) { offset = 0; tcs = new TaskCompletionSource <bool>(); result = connection.BeginRead(0, Math.Min(FaultStringDecoder.FaultSizeQuota, connection.AsyncReadBufferSize), timeoutHelper.RemainingTime(), FramingDuplexSessionChannel.OnIoComplete, tcs); if (result == AsyncCompletionResult.Completed) { tcs.TrySetResult(true); } await tcs.Task; size = connection.EndRead(); } } } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(decoder.CreatePrematureEOFException()); }
public static bool ValidatePreambleResponse(byte[] buffer, int count, ClientFramingDecoder decoder, Uri via) { if (count == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("ServerRejectedSessionPreamble", new object[] { via }), decoder.CreatePrematureEOFException())); } while (decoder.Decode(buffer, 0, count) == 0) { } if (decoder.CurrentState != ClientFramingDecoderState.Start) { return(false); } return(true); }
private static bool ValidateUpgradeResponse(byte[] buffer, int count, ClientFramingDecoder decoder) { if (count == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(System.ServiceModel.SR.GetString("ServerRejectedUpgradeRequest"), decoder.CreatePrematureEOFException())); } while (decoder.Decode(buffer, 0, count) == 0) { } if (decoder.CurrentState != ClientFramingDecoderState.UpgradeResponse) { return(false); } return(true); }
public static async Task DecodeFramingFaultAsync(ClientFramingDecoder decoder, IConnection connection, Uri via, string contentType, TimeSpan timeout) { var timeoutHelper = new TimeoutHelper(timeout); ValidateReadingFaultString(decoder); int size = await connection.ReadAsync(0, Math.Min(FaultStringDecoder.FaultSizeQuota, connection.AsyncReadBufferSize), timeoutHelper.RemainingTime()); int offset = 0; while (size > 0) { int bytesDecoded = decoder.Decode(connection.AsyncReadBuffer, offset, size); offset += bytesDecoded; size -= bytesDecoded; if (decoder.CurrentState == ClientFramingDecoderState.Fault) { ConnectionUtilities.CloseNoThrow(connection, timeoutHelper.RemainingTime()); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( FaultStringDecoder.GetFaultException(decoder.Fault, via.ToString(), contentType)); } else { if (decoder.CurrentState != ClientFramingDecoderState.ReadingFaultString) { throw new Exception("invalid framing client state machine"); } if (size == 0) { offset = 0; size = await connection.ReadAsync(0, Math.Min(FaultStringDecoder.FaultSizeQuota, connection.AsyncReadBufferSize), timeoutHelper.RemainingTime()); } } } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(decoder.CreatePrematureEOFException()); }
private static bool ValidateUpgradeResponse(byte[] buffer, int count, ClientFramingDecoder decoder) { if (count == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(SR.ServerRejectedUpgradeRequest, decoder.CreatePrematureEOFException())); } // decode until the framing byte has been processed (it always will be) while (decoder.Decode(buffer, 0, count) == 0) { // do nothing } if (decoder.CurrentState != ClientFramingDecoderState.UpgradeResponse) // we have a problem { return(false); } return(true); }
public static bool ValidatePreambleResponse(byte[] buffer, int count, ClientFramingDecoder decoder, Uri via) { if (count == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new ProtocolException(SR.Format(SR.ServerRejectedSessionPreamble, via), decoder.CreatePrematureEOFException())); } // decode until the framing byte has been processed (it always will be) while (decoder.Decode(buffer, 0, count) == 0) { // do nothing } if (decoder.CurrentState != ClientFramingDecoderState.Start) // we have a problem { return(false); } return(true); }
public static bool ValidatePreambleResponse(byte[] buffer, int count, ClientFramingDecoder decoder, Uri via) { if (count == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("ServerRejectedSessionPreamble", new object[] { via }), decoder.CreatePrematureEOFException())); } while (decoder.Decode(buffer, 0, count) == 0) { } if (decoder.CurrentState != ClientFramingDecoderState.Start) { return false; } return true; }
private static bool ValidateUpgradeResponse(byte[] buffer, int count, ClientFramingDecoder decoder) { if (count == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(System.ServiceModel.SR.GetString("ServerRejectedUpgradeRequest"), decoder.CreatePrematureEOFException())); } while (decoder.Decode(buffer, 0, count) == 0) { } if (decoder.CurrentState != ClientFramingDecoderState.UpgradeResponse) { return false; } return true; }