Search code examples
c#windowsazureazureservicebusservicebus

windows service bus disable certificate validation


During testing I am trying to connect to a windows service bus which is installed on a azure VM, but getting error

System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.

I tried to disable certificate validation

   ServicePointManager.ServerCertificateValidationCallback += CertificateValidation;

    public static bool CertificateValidation(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors policyErrors)
    {
        return true;
    }

But I am still getting the same error.

How to disable certificate validation while connecting to a remote windows service bus??


Solution

  • On client, we can use Net.TCP, AMQP, or REST over HTTP as the protocol for communication with the Service Bus. Adding event handing for ServerCertificateValidationCallback will only works for REST over HTTP. For the other protocols, you could add following configuration under system.serviceModel section.

    <behaviors>
      <endpointBehaviors>
        <behavior name="DisableSSLCertificateValidation">
          <clientCredentials>
            <serviceCertificate>
              <sslCertificateAuthentication certificateValidationMode="None" />
            </serviceCertificate>
          </clientCredentials>
        </behavior>
      </endpointBehaviors>
    </behaviors>