public JObject SerializeMessage(Message message)
        {
            JObject messageObject = new JObject();

            messageObject.Add("jsonrpc", JToken.FromObject("2.0"));

            if (message.MessageType == MessageType.Request)
            {
                messageObject.Add("id", JToken.FromObject(message.Id));
                messageObject.Add("method", message.Method);
                messageObject.Add("params", message.Contents);
            }
            else if (message.MessageType == MessageType.Event)
            {
                messageObject.Add("method", message.Method);
                messageObject.Add("params", message.Contents);
            }
            else if (message.MessageType == MessageType.Response)
            {
                messageObject.Add("id", JToken.FromObject(message.Id));

                if (message.Error != null)
                {
                    // Write error
                    messageObject.Add("error", message.Error);
                }
                else
                {
                    // Write result
                    messageObject.Add("result", message.Contents);
                }
            }

            return messageObject;
        }
        public JObject SerializeMessage(Message message)
        {
            JObject messageObject = new JObject();

            if (message.MessageType == MessageType.Request)
            {
                messageObject.Add("type", JToken.FromObject("request"));
                messageObject.Add("seq", JToken.FromObject(message.Id));
                messageObject.Add("command", message.Method);
                messageObject.Add("arguments", message.Contents);
            }
            else if (message.MessageType == MessageType.Event)
            {
                messageObject.Add("type", JToken.FromObject("event"));
                messageObject.Add("event", message.Method);
                messageObject.Add("body", message.Contents);
            }
            else if (message.MessageType == MessageType.Response)
            {
                messageObject.Add("type", JToken.FromObject("response"));
                messageObject.Add("request_seq", JToken.FromObject(message.Id));
                messageObject.Add("command", message.Method);

                if (message.Error != null)
                {
                    // Write error
                    messageObject.Add("success", JToken.FromObject(false));
                    messageObject.Add("message", message.Error);
                }
                else
                {
                    // Write result
                    messageObject.Add("success", JToken.FromObject(true));
                    messageObject.Add("body", message.Contents);
                }
            }

            return messageObject;
        }