从Web服务发送多个响应

时间:2016-04-18 09:11:48

标签: c# web-services

我想创建一个以byte []形式接收图像的Web服务,并将它们保存在FileSystem中。

我希望继续发送响应,因为我将文件保存在FileSystem上,以便用户可以在移动设备上显示进度。

目前我已经构建了一个只能接收单个图像的Web服务。

这是保存单张图片的代码 -

[WebMethod]
public string upload(byte[] postedFile, string folderName, string fileName)
{
    try
    {
        string to_post_in = Path.Combine(HttpContext.Current.Server.MapPath("~/"), folderName);

        File.WriteAllBytes(Path.Combine(to_post_in, fileName), postedFile);

        SortedList slResult = new SortedList();
        slResult.Add("0", "Success");

        return  JsonConvert.SerializeObject(slResult);
    }
    catch
    {
        SortedList slResult = new SortedList();
        slResult.Add("1", "Error");

        return  JsonConvert.SerializeObject(slResult);
    }
}

2 个答案:

答案 0 :(得分:1)

您无法在Web服务中的单个功能中执行此操作

为什么不尝试创建以下内容?

功能upload用于保存此类文件列表

public string upload(List<byte[]> postedFile, string folderName, List<string> fileNameList)
{
    //code to save here
}

函数checkUploaded,它将图像名称列表作为参数并检查已保存的图像数量 -

public string checkUploaded(string folderName, List<string> fileNameList)
{
    //add code to check how many images of the list have already been saved
    //and return a percent       
}

答案 1 :(得分:1)

这可能是不可能的!

据我所知,一旦您发回回复,代码就不会继续从该行继续。

您可以执行以下操作 -

  1. 使用相同的代码。
  2. 从iOS设备逐张发送。
  3. 通过这种方式,您将能够确定哪些文件已成功存储,哪些文件无法存储。

    希望它有所帮助!

相关问题