Search code examples
c#azuresolace

Solace connectivity from Azure Web sites


I am facing issue while trying to connect to the Solace server/port(55555) when the code is deployed as an Azure website or a WebJob. The Solace server is within network though connected through a VPN. The same code works fine when deployed on local IIS/ as a console application. The Session is created, but when the Connect() statement is encountered, it does not execute, neither throws error. What has been done:

  1. Port Closure/Firewall issues has been ruled out by checking with Platform team
  2. The LogLevel has been set to Debug and the events for Context, Session & Message has been subscribed to, but the code does not come to any of these events. Also, could not set the LogDelegate method to work with the log4Net methods.
  3. As per Solace documentation, we need to place the libsolclient.dll in the same path as the SolaceSystems.Solclient.Messaging (in the bin folder) Code Sample is below:

    #region Initialize properties
        ContextProperties contextProps = new ContextProperties()
            {
                TimerResolutionInMsecs = 5000
            };
            SessionProperties sessionProps = new SessionProperties()
            {
    
                Host = ConfigurationManager.AppSettings["Host"],
                VPNName = ConfigurationManager.AppSettings["VPNName"],
                UserName = ConfigurationManager.AppSettings["UserName"],
                Password = ConfigurationManager.AppSettings["Password"],
                ReconnectRetries = 2
            };
            #endregion
    
            ContextFactoryProperties cfp = new ContextFactoryProperties()
            {
                // Set log level.
                SolClientLogLevel = SolLogLevel.Debug
            };
    
            //SolLogInfo logInfo = new SolLogInfo()
            //logInfo.LoggerName = logger.Logger.Name;
            //cfp.LogDelegate(logger.Info);
            logger.Info("Going to create ContextFactory instance");
            // Must init the API before using any of its artifacts.
            ContextFactory.Instance.Init(cfp);
    
            logger.Info("SolaceTestQueuePublish initializing...");
    
            #region Create the Context
    
            context = ContextFactory.Instance.CreateContext(contextProps, null);
            {
                #region Create and connect the Session
    
                session = context.CreateSession(sessionProps, SolTest_OnMessage, SolTest_OnSessionEvent);
                {
                    logger.Info("Solace Session Created.");
    
                    try
                    {
                        logger.Info("Trying to connect to Solace now..");
                        ReturnCode returnCode = session.Connect();
                        if (ReturnCode.SOLCLIENT_OK == returnCode)
                        {
                            isSolaceConnected = true;
                            logger.Info("Connected to Solace.Success!");
                        }
                        else
                            logger.Info("Failed to connect Solace! Error Code:" + returnCode.ToString());
                    }
                    catch (Exception ex)
                    {
                        logger.Info("Failed to connect Solace!Error:" + ex.Message + "; Stack:" + ex.StackTrace);
                        //throw;
                    }
    
    
                }
    
                //session.Dispose();
                #endregion
            }
            //context.Dispose();
            #endregion
    

Solution

  • It appears that the issue is due to the Sandbox restriction. All Azure Web Apps (as well as Mobile App/Services, WebJobs and Functions) run in a secure environment called a sandbox. Each app runs inside its own sandbox, isolating its execution from other instances on the same machine as well as providing an additional degree of security and privacy which would otherwise not be available.

    The only way an application can be accessed via the internet is through the already-exposed HTTP (80) and HTTPS (443) TCP ports; applications may not listen on other ports for packets arriving from the internet. However, applications may create a socket which can listen for connections from within the sandbox. For example, two processes within the same app may communicate with one another via TCP sockets; connection attempts incoming from outside the sandbox, albeit they be on the same machine, will fail. Refer the document section ‘Networking Restrictions/Considerations’ for details on this topic.

    Reference: https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#network-endpoint-listening