public override void Invoke(AMFContext context) { AMFDeserializer deserializer = new AMFDeserializer(context.InputStream); deserializer.UseLegacyCollection = _useLegacyCollection; try { AMFMessage amfMessage = deserializer.ReadAMFMessage(); context.AMFMessage = amfMessage; context.MessageOutput = new MessageOutput(amfMessage.Version); if (deserializer.FailedAMFBodies.Length > 0) { AMFBody[] failedAMFBodies = deserializer.FailedAMFBodies; //Write out failed AMFBodies for (int i = 0; i < failedAMFBodies.Length; i++) context.MessageOutput.AddBody(failedAMFBodies[i]); } } catch { Dump(context.InputStream); throw; } }
//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) { MemoryStream memoryStream = new MemoryStream(buffer.Array, buffer.Offset, buffer.Count - buffer.Offset); AMFDeserializer amfDeserializer = new AMFDeserializer(memoryStream); AMFMessage amfMessage = amfDeserializer.ReadAMFMessage(); Message returnMessage = Message.CreateMessage(MessageVersion.None, null); returnMessage.Properties.Add("amf", amfMessage); return returnMessage; }
private AMFMessage LoadBinMessageIntoAmfMessage(byte[] encodedMessage) { AMFMessage message = null; byte[] buffer = encodedMessage; MemoryStream stream = new MemoryStream(buffer); try { message = new AMFDeserializer(stream).ReadAMFMessage(); } catch (DecoderFallbackException) { stream.Position = 0; object content = new AMFReader(stream) { FaultTolerancy = true }.ReadAMF3Data(); message = new AMFMessage(3); message.AddBody(new AMFBody(string.Empty, string.Empty, content)); } return message; }