Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I have used QlikEngine JSON API and exploring how to achieve similar results with the .NET SDK. I have a few questions based on the code snippet below:
Uri uri = new Uri("wss://my_remote_host/jwt/app?transient=");
//virtual proxy
AppIdentifier appId = new AppIdentifier();
appId.AppId = "<SOME APPID>";
appId.AppName = "<SOME APP NAME>";
var senseLocation = Location.FromUri(uri);
senseLocation.AsJwtViaProxy(Guid.NewGuid().ToString(), false);
//hope I can pass a GUID for key
var bearerToken = GetToken();
//getting a bearer token to pass in the header
senseLocation.CustomUserHeaders.Add("Authorization", "bearer " + bearerToken); //passing authorization header
var senseSession = Session.WithApp(appId, SessionType.Default);
QlikConnection conn = new QlikConnection(senseLocation, senseSession);
IEnumerable<string> argNames = new List<string>(); //WHAT ARGS?
string[] arguments = null; //WHAT PARAMS?
var response = await conn.SendAsync(1, "GetDocList", argNames, arguments);
using (IHub hub = senseLocation.Hub())
//SocketException: No such host is known
{
var apps = hub.GetAppList();
foreach (var app in apps)
{
Console.WriteLine(app.AppId + ": " + app.AppName);
}
}
Thanks a ton in advance.
I'm not sure I understand what you mean by proxy in this context. Are you referring to something outside of Qlik Sense, or are you referring to a Qlik Sense Proxy as can be configured through the QMC?
In either case, you typically don't need to do any special configuration for the SDK connection. Just use the same url that you would use in your browser but without the virtual proxy path. That one you put in the "VirtualProxyPath" property for the location. Typically you don't define a port here either.
But you are referring to the "DefaultCredentials", does this mean that you want to log in with your default Windows credentials? If that is the case, then you should use "AsNtlmUserViaProxy" instead of "AsJwtViaProxy".
When you use AsJwtViaProxy, the SDK will set the bearer token for you, so you don't have to explicitly set it. The "key" argument is the token. So a JWT connection typically looks like this:
var location = Location.FromUri("https://my_remote_host");
location.VirtualProxyPath = "jwt";
location.AsJwtViaProxy(key, false);
using (var hub = location.Hub())
{
Console.WriteLine(hub.QTProduct());
}
I notice that you have "/jwt/app?transient=" as part of your URI, and that probably shouldn't be there.
You can use any of the schemes https, http, wss and ws. http and ws will only work if your virtual proxy allows it, but it sounds like you have already enabled that in your case.
You definitely don't want to pass a random GUID as the token, as this is the token that will be used to authenticate you. This page is a good place to go to learn how to generate a valid JWT token:
As for calling the different endpoints, it is rather uncommon to work directly with QlikConnection objects and SendAsync. The code you list in bullet 5 looks fine, but you'll need to get your connection working first.
Thanks a ton for the pointer on using the key argument to pass the token.
The other point I am missing is how to connect to the end point via a HTTP proxy.
If I did this for JSON API, the code would be like below. I have the opportunity to specify a proxy because I am the one creating the websocket object.
TheSocket = new ClientWebSocket();
ICredentials credentials = CredentialCache.DefaultCredentials;
IWebProxy webProxy = new WebProxy("http://myproxy:port" , true);
webProxy.Credentials = credentials;
TheSocket.Options.Proxy = webProxy;
Thanks again.
I'm not sure I understand what you mean by proxy in this context. Are you referring to something outside of Qlik Sense, or are you referring to a Qlik Sense Proxy as can be configured through the QMC?
In either case, you typically don't need to do any special configuration for the SDK connection. Just use the same url that you would use in your browser but without the virtual proxy path. That one you put in the "VirtualProxyPath" property for the location. Typically you don't define a port here either.
But you are referring to the "DefaultCredentials", does this mean that you want to log in with your default Windows credentials? If that is the case, then you should use "AsNtlmUserViaProxy" instead of "AsJwtViaProxy".
To clarify, both "proxies" are applicable in my implementation:
1. Yes there is a web proxy outside of Qlik. My client application (where I intend to use .NET SDK) cannot connect to Qlik servers directly, and therefore need to configure a connection proxy server that sits between the .NET SDK Client and Qlik servers.
2. I also have to use the QlikSense proxy configured using QMC.
So, is it possible specify Web proxy url when connecting QS server, using Qlik Sense .NET SDK?
The latest SDK still has no way to support Web proxy????
For example, enigma-go module added support Web proxy setting as below.
https://github.com/qlik-oss/enigma-go/blob/91568aab445a0c6bd64afc702e9c2fc7b696b806/default_dialer.g...
--------
dialer.CreateSocket = func(ctx context.Context, url string, httpHeader http.Header) (Socket, error) {
gorillaDialer := websocket.Dialer{
Proxy: http.ProxyFromEnvironment, // Will pick the Proxy URL from the environment variables (HTTPS_PROXY).
--------
>I'm not sure I understand what you mean by proxy in this context. Are you referring to something outside of Qlik Sense,
Do you understand Web proxy? For example, the web client program may need to use Web proxy systemm, using http://webproxy:88888, to access web server running in Internet space.
So, I guess that Qlik Sense .NET SDK assembly(Qlik.Sense.JsonRpc.dll) uses .NET's ClientWebSocket class to access Qlik Sense Engine with WebSocket. However, we can not set the Proxy property.
https://docs.microsoft.com/en-us/dotnet/api/system.net.websockets.clientwebsocketoptions.proxy?view=...
@UmeshCIf you use .NET Core 3.0 or later, then I believe you can use the default proxy setting of the HttpClient class to achieve this:
https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.defaultproxy?view=netcore-3.0
Have you tested HttpClient.DefaultProxy Property with ClientWebSocket class?