WCF Restful服务文件上传,支持多平台

时间:2012-06-11 11:10:37

标签: c# android iphone .net wcf

任何人都可以告诉我如何创建一个WCF Rest服务,通过它我可以使用android,iphone& amp; abel将文件上传到服务器WP7。

2 个答案:

答案 0 :(得分:4)

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

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); 
}

答案 1 :(得分:2)

可以使用Android,iphone和WP7访问任何Rest service

一种选择是使用WCFMVC创建Rest POST服务,并将data中的图像作为base64字符串。

相关问题