Could not establish trust relationship for the SSL/TLS secure channel with authority

A frustrating issue I run into occasionally in calling web services on my Windows development machine is “Could not establish trust relationship for the SSL/TLS secure channel with authority”.  I usually have to think back and search on the internet how to fix it.

Certificates can be a little confusing and I’m one who just wants to do as little work as possible to get past irrelevant issues so I can get to what is important.  I know enough about certificates to use them and deploy them but I’m not an expert.  So what I have found works but there may be better solutions.

Anyway, here are a couple of ways I’ve resolved the issue.

First, if you just want to ignore all certificates and you don’t mind a hard-coded solution,  you can add this code to the client before calling the service: System.Net.ServicePointManager.ServerCertificateValidationCallback += delegate { return true; };

A second option is that you can use the manage certificates snap-in.  Navigate to the Personal\Certificates folder and copy the localhost certificate to the Trusted Root Certification Authorities\Certificates folder.

 

 

Tool – EntityFramework Reverse POCO Generator

Recently implemented the “EntityFramework Reverse POCO Generator” in a project. 

Here is the link: https://visualstudiogallery.msdn.microsoft.com/ee4fcff9-0c4c-4179-afd9-7a2fb90f5838

It was easy to do and replaces the bulky edmx as well as makes it easier to keep your POCOs in sync with the database.

The script is editable and the code is available on github.  You can also alter the code for your own purposes.

For my project I modified these settings in the tt file:

  1. ConnectionStringName
  2. ConfigurationClassName
  3. UseCamelCase = false;
  4. Namespace
  5. AddUnitTestingDbContext = false;
  6. AutomaticMigrationsEnabled = false;
  7. AutomaticMigrationDataLossAllowed = false;
  8. Inflector.PluralizationService = null;
  9. Comment out pluralization – search for append

Unfortunately, the database has a security schema name with a period in the name so I had to modify the tool code to accept that but name it without the schema in the name.

After running the tool against the existing projects that reference the POCOs, I had to correct a few POCO elements that were named differently than the EDMX name them.  These all were related to foreign keys.