//One of the two main entry points into the encoder. Called by WCF to decode a buffered byte array into a Message. public override Message ReadMessage(ArraySegment <byte> buffer, BufferManager bufferManager, string contentType) { //Decompress the buffer ArraySegment <byte> decompressedBuffer = DecompressBuffer(buffer, bufferManager); //Use the inner encoder to decode the decompressed buffer Message returnMessage = innerEncoder.ReadMessage(decompressedBuffer, bufferManager); returnMessage.Properties.Encoder = this; return(returnMessage); }
private Message ReadChunkedBufferedMessage(Stream inputStream) { try { return(_encoder.ReadMessage(inputStream, _factory.BufferManager, _factory.MaxBufferSize, _contentType)); } catch (XmlException xmlException) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new ProtocolException(SR.MessageXmlProtocolError, xmlException)); } }
private async Task <Message> DecodeBufferedMessageAsync(ArraySegment <byte> buffer, Stream inputStream) { try { // if we're chunked, make sure we've consumed the whole body if (_contentLength == -1 && buffer.Count == _factory.MaxReceivedMessageSize) { byte[] extraBuffer = new byte[1]; int extraReceived = await inputStream.ReadAsync(extraBuffer, 0, 1); if (extraReceived > 0) { ThrowMaxReceivedMessageSizeExceeded(); } } try { return(_encoder.ReadMessage(buffer, _factory.BufferManager, _contentType)); } catch (XmlException xmlException) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new ProtocolException(SR.MessageXmlProtocolError, xmlException)); } } finally { inputStream.Dispose(); } }
private static Message DecodeSessiongramMessage(MsmqInputSessionChannelListener listener, MsmqInputSessionChannel channel, MessageEncoder encoder, MsmqMessageProperty messageProperty, byte[] buffer, int offset, int size) { Message message2; if (size > listener.MaxReceivedMessageSize) { channel.FaultChannel(); listener.MsmqReceiveHelper.FinalDisposition(messageProperty); throw listener.NormalizePoisonException(messageProperty.LookupId, MaxMessageSizeStream.CreateMaxReceivedMessageSizeExceededException(listener.MaxReceivedMessageSize)); } if ((size + offset) > buffer.Length) { listener.MsmqReceiveHelper.FinalDisposition(messageProperty); throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(System.ServiceModel.SR.GetString("MsmqBadFrame"))); } byte[] dst = listener.BufferManager.TakeBuffer(size); Buffer.BlockCopy(buffer, offset, dst, 0, size); try { Message message = null; using (MsmqDiagnostics.BoundDecodeOperation()) { message = encoder.ReadMessage(new ArraySegment <byte>(dst, 0, size), listener.BufferManager); MsmqDiagnostics.TransferFromTransport(message); } message2 = message; } catch (XmlException exception) { channel.FaultChannel(); listener.MsmqReceiveHelper.FinalDisposition(messageProperty); throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(System.ServiceModel.SR.GetString("MsmqBadXml"), exception)); } return(message2); }
static Message DecodeSessiongramMessage( MsmqInputSessionChannelListener listener, MsmqInputSessionChannel channel, MessageEncoder encoder, MsmqMessageProperty messageProperty, byte[] buffer, int offset, int size) { if (size > listener.MaxReceivedMessageSize) { channel.FaultChannel(); listener.MsmqReceiveHelper.FinalDisposition(messageProperty); throw listener.NormalizePoisonException(messageProperty.LookupId, MaxMessageSizeStream.CreateMaxReceivedMessageSizeExceededException(listener.MaxReceivedMessageSize)); } // Fix for CSDMain bug 17842 // size is derived from user data, check for corruption if ((size + offset) > buffer.Length) { listener.MsmqReceiveHelper.FinalDisposition(messageProperty); throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(SR.GetString(SR.MsmqBadFrame))); } byte[] envelopeBuffer = listener.BufferManager.TakeBuffer(size); Buffer.BlockCopy(buffer, offset, envelopeBuffer, 0, size); try { Message message = null; using (MsmqDiagnostics.BoundDecodeOperation()) { message = encoder.ReadMessage(new ArraySegment <byte>(envelopeBuffer, 0, size), listener.BufferManager); MsmqDiagnostics.TransferFromTransport(message); } return(message); } catch (XmlException e) { channel.FaultChannel(); listener.MsmqReceiveHelper.FinalDisposition(messageProperty); throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(SR.GetString(SR.MsmqBadXml), e)); } }
public static Message DecodeMessage(DuplicateMessageDetector duplicateDetector, MessageEncoder encoder, BufferManager bufferManager, ArraySegment <byte> data, IPEndPoint remoteEndPoint, int interfaceIndex, bool ignoreSerializationException, out string messageHash) { Fx.Assert(data != null, "data can't be null"); Fx.Assert(remoteEndPoint != null, "remoteEndPoint can't be null"); Fx.Assert(encoder != null, "encoder can't be null"); Fx.Assert(bufferManager != null, "bufferManager can't be null"); Message message = null; messageHash = null; if (duplicateDetector == null || !duplicateDetector.IsDuplicate(data, out messageHash)) { try { message = encoder.ReadMessage(data, bufferManager); } catch (XmlException error) { // Don't throw serialization exceptions when the channel supports Multicast if (!ignoreSerializationException) { throw; } FxTrace.Exception.AsWarning(error); } if (message != null) { message.Properties.Add(RemoteEndpointMessageProperty.Name, new RemoteEndpointMessageProperty(remoteEndPoint.Address.ToString(), remoteEndPoint.Port)); NetworkInterfaceMessageProperty networkInterfaceMessageProperty = new NetworkInterfaceMessageProperty(interfaceIndex); networkInterfaceMessageProperty.AddTo(message); } } return(message); }
protected override Message DecodeMessage(byte[] buffer, ref int offset, ref int size, ref bool isAtEOF, TimeSpan timeout) { while (size > 0) { int bytesRead = _decoder.Decode(buffer, offset, size); if (bytesRead > 0) { if (EnvelopeBuffer != null) { if (!object.ReferenceEquals(buffer, EnvelopeBuffer)) { System.Buffer.BlockCopy(buffer, offset, EnvelopeBuffer, EnvelopeOffset, bytesRead); } EnvelopeOffset += bytesRead; } offset += bytesRead; size -= bytesRead; } switch (_decoder.CurrentState) { case ClientFramingDecoderState.Fault: _channel.Session.CloseOutputSession(_channel.GetInternalCloseTimeout()); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(FaultStringDecoder.GetFaultException(_decoder.Fault, _channel.RemoteAddress.Uri.ToString(), _messageEncoder.ContentType)); case ClientFramingDecoderState.End: isAtEOF = true; return(null); // we're done case ClientFramingDecoderState.EnvelopeStart: int envelopeSize = _decoder.EnvelopeSize; if (envelopeSize > _maxBufferSize) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( ExceptionHelper.CreateMaxReceivedMessageSizeExceededException(_maxBufferSize)); } EnvelopeBuffer = _bufferManager.TakeBuffer(envelopeSize); EnvelopeOffset = 0; EnvelopeSize = envelopeSize; break; case ClientFramingDecoderState.EnvelopeEnd: if (EnvelopeBuffer != null) { Message message = null; try { IDisposable activity = ClientDuplexConnectionReader.CreateProcessActionActivity(); using (activity) { message = _messageEncoder.ReadMessage(new ArraySegment <byte>(EnvelopeBuffer, 0, EnvelopeSize), _bufferManager); } } catch (XmlException xmlException) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new ProtocolException(SR.MessageXmlProtocolError, xmlException)); } EnvelopeBuffer = null; return(message); } break; } } return(null); }