WCF RESTful服务文件上传与多平台支持 [英] WCF Restful service file upload with multi-platform support

查看:515
本文介绍了WCF RESTful服务文件上传与多平台支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁能够告诉我,我怎么可以创建一个WCF休息服务,通过它我可以阿贝尔使用Android设备,iPhone和功放文件上传到服务器; WP7。

can anybody please tell me how can i create a WCF Rest service through which i can be abel to upload files to server using android , iphone & WP7.

推荐答案

感谢您的帮助,我能够为多个平台上创建文件上传WCF休息服务。

Thanks for help I was able to create file upload wcf rest service for multiple platform.

public void FileUpload(string fileName, Stream fileStream)
{
    FileStream fileToupload = new FileStream("c:\\FileUpload\\" + fileName, FileMode.Create);

    byte[] bytearray = new byte[10000];
    int bytesRead, totalBytesRead = 0;
    do
    {
        bytesRead = fileStream.Read(bytearray, 0, bytearray.Length);
        totalBytesRead += bytesRead;
    } while (bytesRead > 0);

    fileToupload.Write(bytearray, 0, bytearray.Length);
    fileToupload.Close();
    fileToupload.Dispose();
}

[ServiceContract]
public interface IImageUpload
{
    [OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "FileUpload/{fileName}")]
    void FileUpload(string fileName, Stream fileStream); 
}

这篇关于WCF RESTful服务文件上传与多平台支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆