below is the method implemented in the service class to change basic http send timeout at runtime without using app.config.I have get the value from appsettings.json file.
service class
public class SearchService:ISearchService
{
private int timeout;
public SearchService(IConfigHelper:configHelper)
{
timeout= Convert.ToInt32(configHelper.GetConfigValue("timeoutInMiliSeconds"))
}
public async Task<Search>
{
SeriveClient client=new ServiceClient();
var time = new TimeSpan(timeout);
client.Endpoint.Binding.SendTimeout = time;
client.close();
}
}
GetConfigValue method in the configHelper class is implemented as below.
public string GetConfigValue (string key)
{
var value = _configuration["AppSettings:" + key];
return !string.IsNullOrEmpty(value) ? Convert.ToString(value):string.Empty;
}
appsettings.json file
"AppSettings":{
"timeoutInMiliSeconds":"70000"
}
At timeout= Convert.ToInt32(configHelper.GetConfigValue("timeoutInMiliSeconds")) it throws an exception.And I want to handle it with if-else conditions,without using try catch block.
Can someone please let me know how to do it?
Thankyou.
Aucun commentaire:
Enregistrer un commentaire