public override Task <object> ReadFromStreamAsync(Type type, System.IO.Stream readStream, HttpContent content, System.Net.Http.Formatting.IFormatterLogger formatterLogger)
        {
            if (!content.IsMimeMultipartContent())
            {
                throw new System.Web.Http.HttpResponseException(System.Net.HttpStatusCode.UnsupportedMediaType);
            }

            var parts = content.ReadAsMultipartAsync();

            return(Task.Factory.StartNew <object>(() =>
            {
                object data = null;
                List <KeyValuePair <string, string> > valueCollection = new List <KeyValuePair <string, string> >();
                foreach (var partContent in parts.Result.Contents)
                {
                    if (partContent.Headers.ContentType == null)
                    {
                        var value = partContent.ReadAsStringAsync().Result;
                        var name = partContent.Headers.ContentDisposition.Name;
                        name = name.Substring(1, name.Length - 2);
                        valueCollection.Add(new KeyValuePair <string, string>(name, value));
                    }
                    else if (partContent.Headers.ContentType != null &&
                             partContent.Headers.ContentType.MediaType == "application/json")
                    {
                        var partBody = partContent.ReadAsStringAsync().Result;
                        data = JsonConvert.DeserializeObject(partBody, type);
                        break;
                    }
                }
                if (data == null)
                {
                    if (valueCollection.Count > 0)
                    {
                        data = new FormDataCollection(valueCollection).ConvertToObject(type);
                        //var valueCollectionJson = valueCollection.ToJson();
                        //data = JsonConvert.DeserializeObject(valueCollectionJson, type);
                    }
                }
                return data;
            }));
        }
        public override Task <object> ReadFromStreamAsync(Type type, System.IO.Stream readStream, HttpContent content, System.Net.Http.Formatting.IFormatterLogger formatterLogger)
        {
            var commandType = type;

            if (type.IsAbstract || type.IsInterface)
            {
                var commandContentType = content.Headers.ContentType.Parameters.FirstOrDefault(p => p.Name == "command");
                if (commandContentType != null)
                {
                    commandType = GetCommandType(HttpUtility.UrlDecode(commandContentType.Value));
                }
                else
                {
                    commandType = GetCommandType(HttpContext.Current.Request.Url.Segments.Last());
                }
            }
            var part      = content.ReadAsStringAsync();
            var mediaType = content.Headers.ContentType.MediaType;

            return(Task.Factory.StartNew <object>(() =>
            {
                object command = null;
                if (mediaType == "application/x-www-form-urlencoded" || mediaType == "application/command+form")
                {
                    command = new FormDataCollection(part.Result).ConvertToObject(commandType);
                }
                if (command == null)
                {
                    command = part.Result.ToJsonObject(commandType);
                }
                return command;
            }));
        }
 public override System.Threading.Tasks.Task <object> ReadFromStreamAsync(Type type, System.IO.Stream stream, System.Net.Http.Headers.HttpContentHeaders contentHeaders, System.Net.Http.Formatting.IFormatterLogger formatterLogger)
 {
     return(base.ReadFromStreamAsync(type, stream, contentHeaders, formatterLogger));
 }