Skip to main content
Announcements
Document boards are being consolidated, this board no longer allows NEW documents READ MORE

QlikView Management API - #1 Setting up a Visual Studio project

cancel
Showing results for 
Search instead for 
Did you mean: 
Joe_Bickley
Employee
Employee

QlikView Management API - #1 Setting up a Visual Studio project

Last Update:

Nov 21, 2012 6:40:10 AM

Updated By:

Joe_Bickley

Created date:

Nov 21, 2012 6:40:10 AM

Attachments

Introduction

This document is part of a series of documents that discuss how to use the QlikView Management API. You can find the index for these documents Here.

The Management API is a web service against which you can issue a range of commands to automate management activities on a QlikView environment.  There are a couple of prerequisite set up items to do before you can use it and the web service has to be used in a particular way. This document describes how you can configure a Visual Studio project to work with the web service.

An example starter Visual Studio project pre-configured to use the API is attached to this document. The free versions of Visual Studio can be used although some of the screens described below may be slightly different.

Using the API

Step 1 – Set Permissions


To be able to make calls to the management service the request needs to come from a user context with membership of a specific group on the QlikView server.  For most API calls the user needs to be a member of the “QlikView Management API” group, this groups is not created by the QlikView installer and so must be created and the relevant users added.

Depending on the type of application you are building you need to use an appropriate way of running the code as a particular user.  For example:

  • If you have a desktop application, it can run using the login ID of the current user
  • If you have a web page then either the user ID of the web site OR the user ID of the person browsing can used
  • If you always want a specific user to be used to call commands you can embed this into the code

Further discussion of this subject can be found HERE (TBC)

Step 2 – Create a project & Reference the QlikView Management Web Service


Open Visual Studio and start a new project for the type of solution you want to use.  For the example and instructions provided it is a basic console application but the process works the same for asp.net, WinForms etc.

The first step is to connect the QMS API to visual studio by adding a Service Reference

service.png

Into the service reference dialogue enter the following URL adjusting for your particular QlikView server address -  http://localhost:4799/QMS/Service - click the Go button and it will connect and validate that the service exists.  Provide a meaningful name for this reference, for example QMSAPIService. It should look as below

service2.png 
 

Step 2 – Configure Visual Studio to use a Service Behaviour


The QMS web service requires the presence of a HTTP header containing a “service key” representing your user session with the server.  This must be injected into every request and while this is a fairly complex thing to do, QlikView provides the code required to do this in .net projects.

Firstly in Visual Studio create a new folder called ServiceSupport in the root of the projects folder structure.

Download the attached "ServiceSupportFiles.zip" file and extract the 3 files starting with “ServiceKey…cs”.  Now right click  the folder the folder you created above and click “Add | Existing Item” browse to where you saved the files, select all 3 and click Add.  The structure of your project should now look like the below.

folders.png

Next each of these three files needs to have its namespace edited to match the namespace of your entire project.  So open each file and locate the line that will look like this

namespace QMSAPIStarter.ServiceSupport

The namespace of your project will match the name of the project if you didn’t change it and in the above case the text you would change is QMSAPIStarter, leave the ServiceSupport part present

Next open web.config or app.config depending on the type of project you have.  Locate the opening tag called <system.serviceModel> and immediately after this  paste the below entry

<extensions>

<behaviorExtensions>

<add name="serviceKeyBehavior" type="QMSAPIStarter.ServiceSupport.ServiceKeyBehaviorExtensionElement, QMSAPIStarter, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>

</behaviorExtensions>

</extensions>

<behaviors>

<endpointBehaviors>

<behavior name="ServiceKeyEndpointBehavior">

<serviceKeyBehavior/>

</behavior>

</endpointBehaviors>

</behaviors>

Notice in the code there are TWO references to the namespace for the code we added above, make sure BOTH of these match the namespace of your project.

Finally locate the following block in the config file

<endpoint address="http://localhost:4799/QMS/Service" binding="basicHttpBinding"

bindingConfiguration="BasicHttpBinding_IQMS" contract="QMSAPIService.IQMS"

name="BasicHttpBinding_IQMS" />

Before the closing tag add behaviorConfiguration="ServiceKeyEndpointBehavior"

Save and close the config file.

Step 3 – Create an object to communicate with the API and add the Service Key


The next step is to write the first piece of code to communicate with the web service, handle the service key and from then on the API functions can be used.

Create the item you want to work with, in this example I am creating a simple class and writing code into the Main method, if you are working with a web page you can locate the code, on load or on the click of a button.

At the top of your code page add the following statements to reference the support functions and the API itself (correct namespace accordingly):

using QMSAPIStarter.QMSAPIService;

using QMSAPIStarter.ServiceSupport;

Now into the function you are using paste the below code.  This creates the “QMSClient” object from which all subsequent API calls will be made, and packages the service key required to use it.  Here i have hard coded the URL to QMS Web Service if you leave it out it will pick up the URL from your config file.

            QMSClient Client;

            string QMS = "http://localhost:4799/QMS/Service";

            Client = new QMSClient("BasicHttpBinding_IQMS", QMS);

            string key = Client.GetTimeLimitedServiceKey();

            ServiceKeyClientMessageInspector.ServiceKey = key;

The ServiceKey is the token that represents your session with the API.  Once the token is obtained it is valid for 20 minutes however this period is extended after each call to the API so you should only need to request a key once.

Step 4 – Issue an API command


Now it is possible to issue commands against the API.  Below is a simple function that will ask for the list of services on the QlikView server and print out their names.

            ServiceInfo[] myServices = Client.GetServices(ServiceTypes.All);

            foreach (ServiceInfo service in myServices)

            {

                Console.WriteLine(service.Name);

            }

Build your project and execute it to see the results.    You can now build and run your own applications using the API. 

There are a number of objects, types and methods included in the API - Check out the list of examples to see how they can use - see Here

Labels (1)
Comments
Not applicable

Hi Joe,

thanks for this great entry point into the Management API. However, I found there seems to be a little incosistency in the XML structure App Info. The Visual Studio parser recognizes the child element <serviceKeyBehavior/> as invalid and throws a warning. But one can simply ignore this warning and build and run will just work fine.

I would furthermore add a try/catch around your code to avoid unexpected aborts and cryptic error descriptions.

best regards

Florian

0 Likes
Joe_Bickley
Employee
Employee

Hi Florian,

Thanks for your feedback.  I also get a similar validation warning message, i'll see if i can find out why and if it is a simple thing to correct - like you say it works regardless but it would be tidy to get rid of it.

Regarding the try-catch,  of course this make total sense when build a real application. In fact i wrote this article based on a few real examples which included them but i wanted the examples to use a few lines of code as possible for the sake of clarity and to help people less familiar with programming use them. 

I fully expect the examples to be lifted into a proper applications but i should perhaps make this clearer in he articals.

Joe

0 Likes
Not applicable

Question: How can I be a member of the “QlikView Management API” group?

How can I create it?

0 Likes
Joe_Bickley
Employee
Employee

It is a local windows group on the QlikView server.  Just add it through the window control panel

Not applicable

Thanks a lot!!!

0 Likes
Not applicable

My QMS service is in a server in a virtual machine http://<serverVMachine1>:4799/QMS/Service and when  try to add Service reference I get an error... Just in case....my PC and the serverVMachine1  server are in differents domains.foro1.png

Any clue?

Thanks in advance

0 Likes
Not applicable

Joe, Perfect, you have made QMS simple . Am desperately searching for a post like this.

Its builds and runs perfectly, however am getting error when am running from my local developer system. My QMS hosted in a remote server.

"
The HTTP request is unauthorized with client authentication scheme 'Ntlm'. The authentication header received from the server was 'NTLM'.

"

How to resolve this? your direction or samle codes are welcome. Thanks a lot in advance.

Thanks

Vijay

Not applicable

Hi, Thanks very much for this tut, ive ported it to vb.net but i get an error on:

myServices = Client.GetServices(ServiceTypes.All)

it say's "Service key is missing"... Type: System.ServiceModel.FaultException in mscorlib.dll

but with Client.GetTimeLimitedServiceKey() i get a key and there is no Problem in setting it.

Ive Checked the User-rights, the compiled c# project runs fine. But i cannot program c#.

Any Clues or ideas?

Thank you very much!

EDIT: i uploaded it to codeplex: https://qvmgmtapi.codeplex.com/

0 Likes
regowins
Creator II
Creator II

Hi,

Did you ever figure out  the "Service Key is Missing" issue? I am getting the same error using the attached pre-configured app.

Thanks for the help!

0 Likes
Not applicable

Hi, nope sorry, even the c# project fails with same error now. maybe there is something with my .net setup.. or whatever.

0 Likes
Version history
Last update:
‎2012-11-21 06:40 AM
Updated by: