我有一个 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。
在查看谷歌后,我决定将 MaxResponseContentBufferSize 设置为任意 256000 值。即使这适用于我的本地机器,但在构建框中我收到此错误:找不到方法:'Void System.Net.Http.HttpClient.set_MaxResponseContentBufferSize(Int64)
我不知道现在该怎么办。