Ole*_* Sh 6 asynchronous system.net
我有以下代码:
public class UploadController : ApiController
{
DBRepository _repository = new DBRepository();
public Task<IEnumerable<FileDesc>> Post()
{
string folderName = "UploadedFiles";
string PATH = HttpContext.Current.Server.MapPath("~/" + folderName);
PATH = @"c:\www\qqq";
string rootUrl = Request.RequestUri.AbsoluteUri.Replace(Request.RequestUri.AbsolutePath, String.Empty);
if (Request.Content.IsMimeMultipartContent())
{
var streamProvider = new CustomMultipartFormDataStreamProvider(PATH);
var task = Request.Content.ReadAsMultipartAsync(streamProvider).ContinueWith<IEnumerable<FileDesc>>(t =>
{
if (t.IsFaulted || t.IsCanceled)
{
throw new HttpResponseException(HttpStatusCode.InternalServerError);
}
return fileInfo;
});
return task;
}
else
{
throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotAcceptable, "This request is not properly formatted"));
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是我得到了错误:
错误16'System.Net.Http.HttpContent'不包含'IsMimeMultipartContent'的定义,并且没有可以找到接受类型'System.Net.Http.HttpContent'的第一个参数的扩展方法'IsMimeMultipartContent'(你错过了吗?使用指令或程序集引用?)
错误17'System.Net.Http.HttpContent'不包含'ReadAsMultipartAsync'的定义,并且没有可以找到接受类型'System.Net.Http.HttpContent'的第一个参数的扩展方法'ReadAsMultipartAsync'(你错过了吗?使用指令或程序集引用?)
错误18'System.Net.Http.HttpRequestMessage'不包含'CreateResponse'的定义,并且没有扩展方法'CreateResponse'接受类型'System.Net.Http.HttpRequestMessage'的第一个参数可以找到(你错过了吗?使用指令或程序集引用?)
为什么?我添加了一个程序集System.Net.Http.Formatting.dll并且有
using System.Net.Http.Formatting;
Run Code Online (Sandbox Code Playgroud)
在页面http://msdn.microsoft.com/ru-ru/library/hh834190(v=vs.108).aspx仔细说,这个分机.方法是在System.Net.Http.Formatting(在System.Net.Http.Formatting.dll中)我试图在4.0和4.5下编译项目 - 没有效果.
PS.我有一个使用相同代码的解决方案,它完美地运行.我能做什么?
| 归档时间: |
|
| 查看次数: |
3251 次 |
| 最近记录: |