我在RestSharp上有一些稳定的实现,查询HTTP WebAPI WebService,超时60秒。实际上,这个实现在Windows服务上使用,所以这个WS每天都会收到很多请求。
问题是,有时我会收到一个错误(每天15个aprox。)并且不知道如何处理这个错误,所以所有请求都可以得到答案。 (实际上我正在考虑重试执行)。
Public Sub UpdateQuery(ByVal query As Request)
Dim client As New RestClient(ConfigurationManager.AppSettings("SERVICE_URL") & query.Query)
Dim request = New RestRequest(ConfigurationManager.AppSettings("SERVICE_URL") & query.Query, Method.PATCH)
Dim response As New RestResponse
request.Timeout = 1000 * ConfigurationManager.AppSettings("RequestTimeOut")
request.AddParameter("application/json", query.Body, ParameterType.RequestBody)
response = client.Execute(request)
If response.ErrorException Is Nothing Then
If response.StatusCode = HttpStatusCode.NoContent Then
query.StatusCode = response.StatusCode
Else
query.StatusCode = response.StatusCode
query.ErrorDescr = JObject.Parse(response.Content).SelectToken("error.message.value")
End If
Else
response = client.Execute(request) 'Retry¿?¿?
If response.ErrorException Is Nothing Then
query.StatusCode = response.StatusCode
If response.StatusCode <> HttpStatusCode.NoContent Then
query.ErrorDescr = JObject.Parse(response.Content).SelectToken("error.message.value")
End If
Else
Throw New Exception("UpdateQuery error:, response.ErrorException)
End If
End If
End Sub
收到的例外是这一个(在谷歌上翻译) -
System.Net.WebException : the waiting time of the operation was exceeded
in System.Net.HttpWebRequest.GetResponse ( )
in RestSharp.Http.GetRawResponse ( HttpWebRequest request)
in RestSharp.Http.GetResponse ( HttpWebRequest request)
任何想法都会有所帮助。非常感谢提前。
答案 0 :(得分:0)
显然缺少Maxlength。