WCF Services over HTTPS: Programmatically accept self-signed or invalid SSL certificates

When using WCF Services over HTTPS with a self-signed or invalid SSL certificates WCF could throw get an exception of type SecurityNegotiationException that says:

Could not establish trust relationship for the SSL/TLS secure channel with authority […].

To instruct WCF to accept all certificates use the following code before consuming any services:

ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, errors) => true;

Self-signed certificates are often used in development environments. Due to security reasons, in a production environment you should never use the code above; instead you should always use valid certificates and prohibit any communication in case of certificate problems!