0

这是一个非常初学者的问题,但我不熟悉如何使用 HttpContext.Current.Request.Files

假设我的 webService Url 是:

http://127.0.0.1/iisEntry/myApi.asmx

有人可以快速编写一些关于如何将文件上传到以下网络方法的代码吗?

public void AddDocument(String title)
{            
    var action = new AddDocumentAction
                     {
                         File = HttpContext.Current.Request.Files[0],
                         DocumentTitle = title
                     }
    processor.Process(action);
}
4

1 回答 1

1

HttpContext.Current.Request.Files contains files uploaded with POST request with "multipart/form-data" encoding type. ASMX web service could handle only XML/SOAP based requests, so you will not be able to upload files this way.

Options are:

  • Add byte[] parameter to you web service method and enable MTOM to handle large files.
  • Add separate non-asmx handler (ASP.NET MVC Controller/Action with HttpPostedFileBase) to receive files.
于 2013-10-01T16:53:28.350 回答