I am calling a web api through a dll file which is being used by .net client desktop application. Dll file is written in .Net 4.0
.
Sometimes I get frequent errors on this line.
var postResponse = client.PostAsJsonAsync(path, Input).Result;
After the error message i check IIS and web service log files. As per the log files, the above line of code didn't get to web service because web method logs all activities in its own log file.
Is there a way to avoid timeout errors.
Dll file code
private T CallService<T>(string path)
{
using (var client = new HttpClient())
{
client.BaseAddress = EndpointAddress;
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.Timeout = TimeSpan.FromSeconds(30);
var response = client.PostAsJsonAsync(path, Input).Result;
if (response.IsSuccessful)
{
var serviceResponse = response.Content.ReadAsAsync<T>().Result;
// return service response;
}
else
{
// return default (T)
}
}
}
Web Service Method
[HttpPost]
public CusResponse GetCustomer(CustomerOperationInput input)
{
}
Here is the header data when it times out
{StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Pragma: no-cache
Connection: close
Cache-Control: no-cache
Date: Wed, 06 Nov 2019 11:06:45 GMT
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Content-Length: 36
Content-Type: application/json; charset=utf-8
Expires: -1
}}
Error from IIS trace file
<EventData>
<Data Name="ContextId">{00000000-0000-0000-230F-008000000019}</Data>
<Data Name="ModuleName">ManagedPipelineHandler</Data>
<Data Name="Notification">128</Data>
<Data Name="HttpStatus">500</Data>
<Data Name="HttpReason">Internal Server Error</Data>
<Data Name="HttpSubStatus">0</Data>
<Data Name="ErrorCode">0</Data>
<Data Name="ConfigExceptionInfo"></Data>
</EventData>