我们在使用JsonTextReader
读取数据时遇到以下异常无法从传输连接中读取数据:远程主机强行关闭现有连接。
JsonTextReader jsonReader - 参数
while (hasRecords(jsonReader, JsonToken.StartObject, null, null)) //Row
{
...
//it's ok to read this all into memory - it's just one row's worth of data
JArray values = (JArray)JToken.ReadFrom(jsonReader);
此外,为了更清晰,还包括HttpPost实现的代码
HttpClientHandler handler = new HttpClientHandler() { Credentials = taskProfileInfo.Credential };
HttpClient httpClient = new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(taskProfileInfo.CommandTimeout) };
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response;
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, url);
request.Content = new StringContent(postBody, Encoding.UTF8, "application/json");
response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
response.EnsureSuccessStatusCode();
//using (var responseStream = await response.Content.ReadAsStreamAsync())
//{
// using (var reader = new StreamReader(responseStream))
// {
// responseFromAPI = reader.ReadToEnd();
// }
//}
return new JsonTextReader(new StreamReader(await response.Content.ReadAsStreamAsync()));
感谢任何人可以帮助我们..
编辑:请注意我们可以在本地调试它并且工作正常。仅在Azure云服务中以辅助角色运行时才出现问题。
答案 0 :(得分:2)
我终于解决了这个问题。只是为了关闭它(可能会帮助某人) -
After doing remote debugging我们发现了以下内部异常: {“请求已中止:请求已取消。”}
并且,此问题的根本原因是我们确实将超时设置为小于实际读取(JsonTextReader)操作所需的时间。以下代码行设置超时:
HttpClient httpClient = new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(taskProfileInfo.CommandTimeout) };
因此,FIX将增加超时值,以便在读取数据时不会取消请求。
答案 1 :(得分:0)
我固定增加了Web配置中的秒数,这是另一种选择:
sessionState timeout="50"