c# - 多平台支持的 WCF Restful 服务文件上传

标签 c# android iphone .net wcf

谁能告诉我如何创建一个 WCF Rest 服务,通过它我可以使用 android、iphone 和 WP7 将文件上传到服务器。

最佳答案

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

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

关于c# - 多平台支持的 WCF Restful 服务文件上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10978961/

相关文章:

c# - 无法从 HttpContextBase 转换为 HttpContextBase

java - 如何通过sqlite数据库中的ID删除ListViews项目

android - 将字符串从一个 Activity 传递到 Android 中的另一个 Activity

iphone - 如何对相机胶卷中的照片进行方形剪切?

c# - 使用 AutoMapper 映射 "LinkedList"

c# - 使用 hang-fire 和 ASP.NET Core 发送每日摘要电子邮件

android - 是否可以使用彩信在 Android 中播放互联网广播?

ios - SpriteKit 背景 PNG,Alpha 显示黑色

iphone - 来自 UIView 区域的 UIImage

c# - 无论 C# 中的基础类型如何,System.Enum 值的一般处理