6 Replies Latest reply: Oct 16, 2017 10:08 PM by 艺 夏 RSS

    Connect to Qlik Sense via .NET SDK

    艺 夏

      Hi All,

       

      I refer to the following pages to try to connect Qlik Sense: Sample code for how to connect to Qlik Sense ‒ Qlik Sense, but I got below error:

      'The remote certificate is invalid according to the validation procedure.'


      I found the solution in Troubleshooting connection ‒ Qlik Sense and have installed the certificate on my local machine, it still doesn't work. My code is like below:


      using System;

      using Qlik.Engine;

      using Qlik.Engine.Communication;

      using System.Net;

      using System.Net.Security;

       

       

      namespace ConnectServerNTLM

      {

          class Program

          {

              static void Main(string[] args)

              {

                  var uri = new Uri("https://w12qs");

       

                  if (args.Length > 0)

                  {

                      uri = new Uri(args[0]);

                  }

       

                  ILocation location = SetupConnection(uri);

                  PrintQlikSenseVersionNumber(location);

              }

       

              private static ILocation SetupConnection(Uri uri)

              {

                  ILocation location = Qlik.Engine.Location.FromUri(uri);

       

                  var domain = "myDomain";

                  var user = "myUserID";

                  var pwd = "myPassword";

       

       

                  location.AsNtlmUserViaProxy(proxyUsesSsl: uri.Scheme.Equals(Uri.UriSchemeHttps), loginCredentials: new NetworkCredential(user, pwd, domain));

       

       

                  return location;

              }

       

       

              private static void PrintQlikSenseVersionNumber(ILocation location)

              {

                  try

                  {

                      using (IHub hub = location.Hub(noVersionCheck: true))

                      {

                          Console.WriteLine(hub.ProductVersion());

                      }

                  }

                  catch (CommunicationErrorException cex)

                  {

                      Console.WriteLine("Can not connect to Qlik Sense instance, check that Qlik Sense is running." + Environment.NewLine + cex.Message);

                  }

                  catch (Exception ex)

                  {

                      Console.WriteLine("General error." + Environment.NewLine + ex.Message);

                  }

                  Console.ReadLine();

              }

          }

      }

       

      Thanks & Regards,

      Shyee