2

I want to create a WCF-RESTful web service method,in which i need to upload an image(multipart-form data) along with some other information (in JSON format). This web service will be accessed by android and iPhone application to send Image and json information as

{ "description":"blah blah", "id"=123,"Comments":"blah blah" }

at the same request. My service input will be Stream,I want to read both image and the above json content from the stream itself.

            StreamReader reader = new StreamReader(fileStream);
            jsonData = HttpUtility.UrlDecode(reader.ReadToEnd());
            byte[] buffer = new byte[10000];
            int bytesRead, totalBytesRead = 0;
            do
            {
                bytesRead = fileStream.Read(buffer, 0, buffer.Length);
                totalBytesRead += bytesRead;
            } while (bytesRead > 0);

How can i read the Passed JSON string from the Stream?

  • For REST, leave to WCF, Web API is much simpler – cuongle Mar 01 '13 at 06:59
  • what i want here is that, i am passing an image(as attachment) as multipart-form data also a json data as in question.Here in web service i want to get both JSON data and image which passed from client application(using multi part form data ) as well.how can i get it done from webservice, please help me with code or link to any solution. – user2122501 Mar 01 '13 at 09:15

1 Answers1

1

You can use DataContractJsonSerializer. Or if you want more control over serialization Json.Net

paramosh
  • 2,258
  • 1
  • 15
  • 23
  • Yeah, I am using JSON.net for serialization/deserialization. But what i want here is that, i am passing an image(as attachment) as multipart-form data also a json data as in question.Here in web service i want to get both JSON data and image which passed from client application(using multi part form data ) as well.how can i get it done from webservice, please help me with code or link to any solution. – user2122501 Mar 01 '13 at 09:11
  • look at this http://stackoverflow.com/questions/9734941/upload-file-from-html-form-multipart-form-data-to-wcf-rest-service-as-a-stream – paramosh Mar 01 '13 at 10:33