title: "Could not establish trust relationship for the SSL/TLS secure channel." Exception on signalr2.2, https, .net client, custom certificate
body: <p>I got some exception in testing signalr .net client with custom self-signed certificate.<br>
  There was no exception on http.<br>
  Is there any problem in setting up the self-signed certificate in my code?<br>
  Note that, there is no problem in my certificate file because it runs my https mvc sites well.  </p>
  
  <p><strong>server side code : asp.net, azure local fabric</strong>  </p>
  
  <pre><code>[assembly: OwinStartup(typeof(BookohWebRole.Startup))]
  namespace BookohWebRole
  {
      public class Startup
      {
          public void Configuration(IAppBuilder app)
          {
              var hubConfiguration = new HubConfiguration();
              hubConfiguration.EnableDetailedErrors = true;
              hubConfiguration.EnableJavaScriptProxies = false;
              //GlobalHost.HubPipeline.AddModule(new ErrorHandlingPipelineModule());
              app.MapSignalR(hubConfiguration);
          }
      }
  }
  
  public class ChatHub : Hub
  {
      public override Task OnConnected()
      {
          Trace.TraceInformation("OnConnected");
          var authToken = Context.QueryString.Get("AuthToken");
          Trace.TraceInformation("authToken : " + authToken);
          return base.OnConnected();
      }
  
      public override Task OnDisconnected(bool stopCalled)
      {
          Trace.TraceInformation("OnDisconnected");
          return base.OnDisconnected(stopCalled);
      }
  
      public override Task OnReconnected()
      {
          Trace.TraceInformation("OnReconnected");
          var authToken = Context.QueryString.Get("AuthToken");
          Trace.TraceInformation("authToken : " + authToken);
          return base.OnReconnected();
      }
  
      public void Send(string name, string message)
      {
          Trace.TraceInformation("Context.ConnectionId : " + Context.ConnectionId);
          Clients.All.onSend(name, message);
      }
  }
  </code></pre>
  
  <p><strong>client side code : .net client, unit test method</strong>  </p>
  
  <pre><code>[TestMethod]
  public void chat()
  {
      var ev = new AutoResetEvent(false);
  
      Task.Run(async () =&gt;
      {
          try
          {
              ServicePointManager.DefaultConnectionLimit = 10;
              var queryString = new Dictionary&lt;string, string&gt;();
              queryString.Add("AuthToken", Guid.NewGuid().ToString());
  
              //https://localhost:44302/
              //http://localhost:22792/
  
              var hubConnection = new HubConnection("https://localhost:44302/");
              hubConnection.Credentials = CredentialCache.DefaultCredentials;
              hubConnection.AddClientCertificate(X509Certificate.CreateFromCertFile("bookoh.cer"));
              hubConnection.TraceLevel = TraceLevels.All;
              hubConnection.TraceWriter = Console.Out;
              IHubProxy chatHubProxy = hubConnection.CreateHubProxy("ChatHub");
              await hubConnection.Start();
  
              chatHubProxy.On&lt;string, string&gt;("onSend", (name, message) =&gt;
              {
                  Trace.TraceInformation("onSend name : " + name);
                  Trace.TraceInformation("onSend message : " + message);
                  ev.Set();
              });
  
              Trace.TraceInformation("chatHubProxy.Invoke");
              await chatHubProxy.Invoke("Send", "hhd2002", "hello");
          }
          catch (Exception ex)
          {
              Trace.TraceInformation("ex : " + ex);
          }
      });
  
      ev.WaitOne();
  }
  </code></pre>
  
  <p><strong>full exception message on client program</strong>  </p>
  
  <pre><code> vstest.executionengine.x86.exe Information: 0 : ex : System.Net.Http.HttpRequestException: An error occurred while sending the request. ---&gt; System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. ---&gt; System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
   at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
   at System.Net.PooledStream.EndWrite(IAsyncResult asyncResult)
   at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
  </code></pre>