I have got two generic methods to call against a service. Depending on call, some methods return an object (passed in params), some don't (void). Can this be further improved? I have got to this point after refactoring a lot and removing anything which was repeated.
private static TResponse ServiceCall<TObjectToPass, TResponse>(
Func<TObjectToPass, TResponse> func,
TObjectToPass obj)
{
var temp = ServicePointManager.ServerCertificateValidationCallback;
ServicePointManager.ServerCertificateValidationCallback +=
(sender, certificate, chain, errors) => true;
var r = func(obj);
ServicePointManager.ServerCertificateValidationCallback = temp;
return r;
}
private static void ServiceCall<TObjectToPass>(
Action<TObjectToPass> func,
TObjectToPass obj)
{
var temp = ServicePointManager.ServerCertificateValidationCallback;
ServicePointManager.ServerCertificateValidationCallback +=
(sender, certificate, chain, errors) => true;
func(obj);
ServicePointManager.ServerCertificateValidationCallback = temp;
}
ServerCertificateValidationCallback
delegate to always validate certificates regardless of the certificate? That's not really what you're doing there. \$\endgroup\$true
. \$\endgroup\$