Mqtt .Net client running in Windows Service

I have created a .Net Windows Service in C#, using Frame 4.6.1.
The service on my local box works perfectly, publishing/subscribing to messages to/from the Broker.
However once I deploy my x64 release version to another box, there’s NO connection to the Broker any longer.
I am logging lots of debug messages, but there are NO errors.

This is what the EMQX Monitor UI looks like with my 3 client connections:

Yet my 2nd .NetWinSvc NEVER gets connected.

It’s the same .net code, only I compile x64 Release version before deploying to my other box.

  public void CreateThreadAndRun()
      Thread m_Thread = new Thread(new ThreadStart(StartPublisherAndSubscriber));
      m_Thread.Name = "MT";
      m_Thread.Priority = ThreadPriority.Highest;

  private void StartPublisherAndSubscriber()

public async void StartPublisher()
    var mqttFactory = new MqttFactory();
    this.managedMqttClientPublisher = mqttFactory.CreateManagedMqttClient();

    // If tls is enabled in app.config, we use wss with cert file
    if (MqttUseTls)
        var managedClientOptions = WsSecureClientOptions();
        await this.managedMqttClientPublisher.StartAsync(managedClientOptions);
        var insecureOptions = WsInsecureOptions();
        await this.managedMqttClientPublisher.StartAsync(
            new ManagedMqttClientOptions
                ClientOptions = insecureOptions

    applog.Debug($"In StartPublisher()");

    Publish(defaultMessage + " - " + this.hostName, this.topicThisHost);

public ManagedMqttClientOptions WsSecureClientOptions()
        string assemblyPath = Path.GetDirectoryName(Assembly.GetAssembly(typeof(MqttService)).CodeBase);

        // Building out the secure wss url (both pfx/crt certificate file types appear to work here)
        var url = $"{mqttBrokerAddress}:{mqttPort}/mqtt";
        X509Certificate2 x509Cert = null;
        var file = CertificateFileName;
        var filePath = Path.Combine(assemblyPath, file).Remove(0, 6);

        // pfx file contains both pub and priv keys (needs pswd); crt file only has pub key (no pswd req'd)
        if (Path.GetExtension(CertificateFileName.ToLower()) == ".pfx") {
            // using a PFX cert file via the X509 class
            x509Cert = new X509Certificate2(filePath, CertificatePwd);
        else if (Path.GetExtension(CertificateFileName.ToLower()) == ".crt")
            x509Cert = new X509Certificate2(filePath);

        //var caFile = "";            // PULLING FROM APP.CONFIG
        //var certFilePath = Path.Combine(assemblyPath, caFile).Remove(0, 6);

        var clientOptionsBldr = new MqttClientOptionsBuilder()
                                    .WithCredentials(mqttClientUser, mqttClientPswd)
                                    .WithCredentials(mqttClientUser, mqttClientPswd)
                                        new MqttClientOptionsBuilderTlsParameters()
                                            UseTls = true,
                                            SslProtocol = System.Security.Authentication.SslProtocols.Tls12,
                                            Certificates = new List<X509Certificate2>() { x509Cert}                                           
        ManagedMqttClientOptions managedClientOptions = null;
            applog.Debug($"In WsSecureClientOptions(), about to Build Publisher - ${url}");
            managedClientOptions = new ManagedMqttClientOptionsBuilder()
        catch (Exception ex)
            applog.Error("CERT ERROR ! Exception in WsSecureClientOptions() " + ex.Message);
        return managedClientOptions;

It may be that the architecture is different, resulting in the wrong format of the final serialized message?

Firstly, the emqx dashboard shows NO client connection from that Service (only from my local box).
That server has an old Windows server version.
However, the latest one I just tested with is an OptiPlex 3060, Win 10 Pro. Still not connecting to broker !
Can you be more specific re: the architecture? Or is there a specific way to OPEN the 8084 ws port?

Thank you.

I suggest you track the client in EMQX to get more detailed logs to help us analyze, you can refer to Trace.

I’m using the new Serverless cloud broker in beta, and I don’t see any Log Trace options as per your docs - " On EMQX Dashboard, you can click DiagnoseLog Trace…"

Sory, If you are using EMQX Cloud Serverless, currently you can only locate specific problems by capturing network packets.