/// <summary>
        /// Encodes the parameters.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <returns>System.Byte[].</returns>
        public override byte[] EncodeParameters(object[] parameters)
        {
            byte[] body;
            using (MemoryStream ms = new MemoryStream())
            {
                using (StreamWriter sw = new StreamWriter(ms, Encoding.UTF8))
                {
                    using (JsonWriter writer = new JsonTextWriter(sw))
                    {
                        int index = -1;
                        writer.WriteStartObject();
                        foreach (var parameter in this.OperationParameters)
                        {
                            object paramValue = parameters[++index];
                            writer.WritePropertyName(parameter.Name);

                            if (paramValue == null)
                            {
                                serializer.Serialize(writer, null);
                            }
                            else
                            {
                                JToken current = JToken.FromObject(paramValue, serializer);
                                JsonFormatterUtility.JTokenToSerialize(current);
                                serializer.Serialize(writer, current);
                            }
                        }
                        writer.WriteEndObject();
                        writer.Flush();
                    }
                }
                body = ms.ToArray();
            }
            return(body);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Encodes the reply.
 /// </summary>
 /// <param name="parameters">The parameters.</param>
 /// <param name="result">The result.</param>
 /// <returns>System.Byte[].</returns>
 public override byte[] EncodeReply(object[] parameters, object result)
 {
     byte[] body;
     using (MemoryStream ms = new MemoryStream())
     {
         using (StreamWriter sw = new StreamWriter(ms, Encoding.UTF8))
         {
             using (JsonWriter writer = new JsonTextWriter(sw))
             {
                 if (result == null)
                 {
                     serializer.Serialize(writer, null);
                 }
                 else
                 {
                     JToken token = JToken.FromObject(result, serializer);
                     JsonFormatterUtility.JTokenToSerialize(token);
                     serializer.Serialize(writer, token);
                 }
                 writer.Flush();
             }
         }
         body = ms.ToArray();
     }
     return(body);
 }