0

We have the following mixed-environment scenario (Azure and LAN):

  1. Azure Web App calls a method in the Azure API (triggered by some user action in the web app).
  2. This Azure API then establishes a SignalR HubContext connection .
  3. The HubContext broadcasts a message.
  4. The SignalR client (consuming the message) is a Windows Service installed on a machine on the LAN, behind the firewall.

Our client is complaining that the connection often breaks, and therefore several messages are missing on a daily basis.

Here is a test method in the Azure API, which attempts to broadcast a message:

using Microsoft.AspNet.SignalR;
using System;
using System.IO;
using System.Net.Http.Headers;
using System.Reflection;
using System.Runtime.Caching;
using System.Text;
using System.Web.Http;
using System.Xml;
...

namespace MyTestAPI.Controllers

    [AllowCrossSiteJson]
    [RoutePrefix("api/Test")]
    public class HL7Controller : ApiController
    
      [HttpGet]
      [Route("TestSignalR")]
      public IHttpActionResult TestSignalR()
      {
          string reportData = $"<TestReport>This is a test message generated on { DateTime.Now }.</TestReport>";
          var hubContext = GlobalHost.ConnectionManager.GetHubContext<HL7Hub>();
          hubContext.Clients.All.SendReportData(reportData);
          return Ok(reportData);
      }
     ...
  }
  

And in the client's environment, there's a Win Service installed - it acts as the SignalR Client enter image description here

And here's a snippet of our H..NotificationsService solution (vs2019, Framework 4.6.1)

using log4net.Ext.EventID;
using Microsoft.AspNet.SignalR.Client;
using System;
using System.Configuration;
using System.Diagnostics;
using System.Net;
using System.ServiceProcess;
using System.Threading;

namespace H_NotificationSrv
{
    public partial class H_NotificationService : ServiceBase
    
      public async void StartListner()
              {
                  try
                  {
                      var hubConnection = new HubConnection(hl7APIUrl);
                      hubConnection.Credentials = CredentialCache.DefaultNetworkCredentials;
                      var hubProxy = hubConnection.CreateHubProxy("MyTestHub");
                      hubProxy.On<string>("SendReportData", reportData =>
                      {
                          SendReportDataToSomeone(reportData);
                      });
                      await hubConnection.Start();                
                  }
                  catch (Exception ex)
                  {
                      string errorMessage = ex.Message;
                      if (ex.InnerException != null)
                          errorMessage += " Inner Exception: " + ex.InnerException.Message;
                      applog.Error(errorMessage);
                  }
              }
       }
}
bob.mazzo
  • 5,183
  • 23
  • 80
  • 149

0 Answers0