如何使用网络服务将文件从WP7上传到网络服务器?此外,当文件存在并被处理时,如何将处理后的文件下载回WP7设备?
答案 0 :(得分:3)
好吧,你可以给我们一些关于你的web服务的更多线索,它是asmx,wcf,php,java吗?它有wsdl还是你正在使用REST?
无论如何,我会做一些假设,因为如果你有一个wsdl,那么你只需要添加一个web引用并使用它。如果您需要编写自己的上传器,可以使用WebClient类将数据推送到Web服务。
// 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);