【发布时间】:2012-07-23 18:53:06
【问题描述】:
我有一个 webapi
public ISearchProviderCommandResult ExecuteCommand(ISearchProviderCommand searchCommand)
{
//serialize the object before sending it in
JavaScriptSerializer serializer = new JavaScriptSerializer();
string jsonInput = serializer.Serialize(searchCommand);
HttpClient httpClient = new HttpClient() { BaseAddress = new Uri(ServiceUrl), MaxResponseContentBufferSize = 256000 };
StringContent content = new StringContent(jsonInput, Encoding.UTF8, "application/json");
HttpResponseMessage output = httpClient.PostAsync(ServiceUrl, content).Result;
//deserialize the output of the webapi call
SearchProviderCommandResult searchResult = serializer.Deserialize<SearchProviderCommandResult>(output.Content.ReadAsStringAsync().Result);
return searchResult;
}
在我的本地机器上,无论我是否设置 MaxResponseContentBufferSize,它似乎都以我想要的方式检索数据。但是在我们的构建环境中,如果我不设置 MaxResponseContentBufferSize ,我会收到此错误: 无法向缓冲区写入超过配置的最大缓冲区大小的字节数:65536。
在 google 上查看后,我决定将 MaxResponseContentBufferSize 设置为任意 256000 值。即使这在我的本地机器上有效,但在构建框上我收到此错误: 找不到方法:'无效 System.Net.Http.HttpClient.set_MaxResponseContentBufferSize(Int64)
我现在不知道该怎么办。
【问题讨论】:
-
这段代码是干什么用的?对于 ASP.NET 应用程序或任何其他应用程序?
-
是的,它的 asp.net web api 代码。我们根据我在 Anand 的帖子中的 cmets 解决了这个问题。
标签: httpclient asp.net-mvc-4 asp.net-web-api