Edward
Edward

Reputation: 7424

Uploading files from WP7 device to a web server using a web service?

How do you upload files from WP7 to a web server using a web service? Also when the file is there and is processed how can you download the processed file back down to the WP7 device?

Upvotes: 0

Views: 906

Answers (1)

jmservera
jmservera

Reputation: 6682

Well, you could give us some more clues about how is your webservice, is it an asmx, wcf, php, java? Does it have a wsdl or you are using REST?

Anyway, I will do some assumptions, because if you have a wsdl then you only have to add a web reference and use it. If you need to write your own uploader you can use, for example, the WebClient class for pushing data to your webservice.

// I assume you have the image into a stream called imageStream
// and that you provide your url into the serviceUri variable

WebClient client = new WebClient();

//here you indicate what to do when the stream is opened
client.OpenWriteCompleted += (sender, e) =>
{
  //now write the data
  //in e.Result you have the destination stream

  byte[] buffer = new byte[32768];
  int readCount;

  while ((readCount = imageStream.Read(buffer, 0, buffer.Length)) != 0)
  {
    e.Result.Write(buffer, 0, readCount);
  }
  e.Result.Close();
  imageStream.Close();
};

 //and here the call that starts your async operation
 client.OpenWriteAsync(serviceUri);

Upvotes: 3

Related Questions