Пример #1
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.Buffer = true;

             Message message = null;
             try
             {
            Deserializer deserializer = new Deserializer(context.Request.InputStream);
            message = deserializer.Deserialize();
             }
             catch (Exception ex)
             {
            log.Error("An error occured will deserializing the AMF stream", ex);
            throw;
             }
             foreach (Body body in message.Bodies)
             {
            Response response = new Response();
            try
            {
               response.Data = body.Invoke();
               response.ReplyMethod = body.Target + "/onResult";
            }
            catch (Exception ex)
            {
               log.Error("An error occured while executing the package", ex);
               response.Data = new AmfError(ex);
               response.ReplyMethod = body.Target + "/onStatus";
            }
            message.Response.Add(response);
             }
             context.Response.ContentType = "application/x-amf";
             try
             {
            Serializer serializer = new Serializer(context.Response.OutputStream);
            serializer.Serialize(message);
             }
             catch (Exception ex)
             {
            log.Error("An error occured will serializing to the AMF stream", ex);
            throw;
             }
             context.Response.Flush();
             context.Response.End();
        }
Пример #2
0
        public static byte[] SerializeBytes(string method, string target, object data)
        {
            //data
            var msData = new MemoryStream();
            var ser2 = new Serializer(msData);
            ser2.WriteData(data);
            byte[] b = msData.ToArray();

            var msMain = new MemoryStream();
            var ser = new Serializer(msMain);
            ser.WriteUInt16(3); //version
            ser.WriteUInt16(0); //0 headers
            ser.WriteUInt16(1); //1 body
            //body
            ser.WriteString(method);
            ser.WriteString(target);
            ser.WriteUInt32((uint)b.Length);
            msMain.Write(b, 0, b.Length);
            return msMain.ToArray();
        }