private static void ProcessPostRequest(HttpRequest request, HttpResponse response, HttpSessionState session)
        {
            response.ContentType = "application/octet-stream";

            var memoryStream = new MemoryStream();
            var output = new DataOutputStream(memoryStream);

            try
            {
                var input = new DataInputStream(request.InputStream);
                var version = request.Headers["version"];
                if (version != null)
                {
                    if (!HttpProcessor.PROTOCOL_VERSION.Equals(version, StringComparison.Ordinal))
                        throw new IOException(String.Format(
                            CultureInfo.CurrentCulture,
                            Resources.IO_InvalidProtocolVersion,
                            version,
                            HttpProcessor.PROTOCOL_VERSION));
                }

                if (input.ReadInt16() == HttpProcessor.INVOCATION_CODE)
                    InvokeMethod(session, input.ReadInt32(), input, output);
                input.Close();
            }
            catch (Exception e)
            {
                if (output == null)
                    output = new DataOutputStream(response.OutputStream);

                output.WriteInt16(HttpProcessor.RESULT_EXCEPTION);
                Debug.WriteLine(e.StackTrace);
                output.WriteString(e.ToString());
            }

            response.SetContentLength(memoryStream.Length);

            try
            {  
                var data = new Byte[memoryStream.Length];
                memoryStream.Seek(0, SeekOrigin.Begin);
                memoryStream.Read(data, 0, data.Length);
                response.OutputStream.Write(data, 0, data.Length);
            }
            finally
            {
                if (output != null)
                    output.Close();
                response.OutputStream.Close();
            }
        }