使用Web服务将文件从WP7设备上传到Web服务器?

问题描述:

如何使用Web服务将文件从WP7上传到Web服务器?当文件在那里并且被处理时,如何将处理后的文件下载回WP7设备?使用Web服务将文件从WP7设备上传到Web服务器?

那么,你可以给我们一些关于你的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); 
+0

对不起,不具体。我正在上传和下载文本文件。过程相对相同吗? – loyalpenguin 2011-04-23 18:59:15

+0

@loyalpenguin是的,它不会改变,如果它是一个文本文件,你只是创建一个流和流,但它取决于你的web服务是如何完成的。它可以使用GET或POST吗? – jmservera 2011-04-23 19:02:36

+0

我知道它的工作。另外你提供的脚本对另一块很有用。谢谢你的时间。 – loyalpenguin 2011-04-25 17:38:31