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
regowins
Creator II
Creator II

Hi, so after some trial and error I found out that  this piece of the code was missing after adding the service reference.

behaviorConfiguration="ServiceKeyEndpointBehavior

It needs to be put in the  app.config file as stated above.

Now the project seems to be working correctly and I can see a list of serverices.

0 Likes
regowins
Creator II
Creator II

Hi Iamxvijay,

Were you able to figure out this issue?  I am getting the same error. I believe it has to do with some setting in the app.config file and security of the server.

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

"

Thanks!

0 Likes
Not applicable

Hi Ashwin Rego,

I just have the same problem as yours (http://grab.by/w5qk). Can you suggest how to solve it?

Thanks in advance

0 Likes
Not applicable

Hi,

We are getting this error after following the above steps. Any advice?

Error 2 The type 'System.Configuration.ConfigurationElement' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.


Thanks!

0 Likes
Not applicable

Have you added namespace system.configuration?

0 Likes
rhd
Support
Support

I have gone through this completely to add into a Support Oriented Windows Form and I am having the same issue with the Service Key is missing.

I can do a MessageBox.Show(key + "\r\n" + ServiceKeyClientMessageInspector.ServiceKey); and I get both values which are exactly the same, but as soon as I try to do Client.GetServices(ServiceTypes.All) it throws the Service Key is missing error.

I do have the "<endpoint address="http://localhost:4799/QMS/Service" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IQMS" contract="QMSAPIService.IQMS" name="BasicHttpBinding_IQMS" behaviorConfiguration="ServiceKeyEndpointBehavior" />" code in the app.config as well as all of the other entries that are shown above except for the "<serviceKeyBehavior/>". When I put this in then it throws an error on that line.

Can someone steer me in the correct direction to get past this missing Key?

Thank you,

Rick

0 Likes
regowins
Creator II
Creator II

It has been a while but here is an example of my app.config file. Maybe you find something useful.

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

 

    <system.serviceModel>

     

      <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>

     

      <bindings>

        <basicHttpBinding>

          <binding name="BasicHttpBinding_IQMS">

            <security mode="TransportCredentialOnly">

              <transport clientCredentialType="Ntlm" />

            </security>

          </binding>

          <binding name="BasicHttpBinding_IQTService">

            <security mode="TransportCredentialOnly">

              <transport clientCredentialType="Ntlm" />

            </security>

          </binding>

        </basicHttpBinding>

      </bindings>

        <client>

            <endpoint address="http://3155-2024:4799/QMS/Service" binding="basicHttpBinding"

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

                name="BasicHttpBinding_IQMS" behaviorConfiguration="ServiceKeyEndpointBehavior"/>

            <endpoint address="http://3155-2024:4799/ANY/Service" binding="basicHttpBinding"

                bindingConfiguration="BasicHttpBinding_IQTService" contract="QMSAPIService.IQTService"

                name="BasicHttpBinding_IQTService" />

        </client>

    </system.serviceModel>

</configuration>

0 Likes
rhd
Support
Support

Thank you Ashwin,

When I add the <serviceKeyBehavior/> tag in the following:

<behaviors>

<endpointBehaviors>

<behavior name="ServiceKeyEndpointBehavior">

<serviceKeyBehavior/>

</behavior>

</endpointBehaviors>

</behaviors>

I get the following error:

************** Exception Text **************

  1. System.Configuration.ConfigurationErrorsException: The type 'QlikViewFileAdmin.ServiceSupport.ServiceKeyBehaviorExtensionElement, QlikViewFileAdmin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' registered for extension 'serviceKeyBehavior' could not be loaded. (C:\Users\rhd\Documents\SharpDevelop Projects\QlikViewFileAdmin-VS2013\QlikViewFileAdmin\bin\Release\QlikSupportAdmin.exe.Config line 12)

   at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)

   at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)

   at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)

   at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)

  at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)

   at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)

   at System.Configuration.ConfigurationManager.GetSection(String sectionName)

   at System.ServiceModel.Activation.AspNetEnvironment.UnsafeGetSectionFromConfigurationManager(String sectionPath)

   at System.ServiceModel.Configuration.ConfigurationHelpers.UnsafeGetAssociatedSection(ContextInformation evalContext, String sectionPath)

   at System.ServiceModel.Description.ConfigLoader.LookupChannel(ContextInformation configurationContext, String configurationName, ContractDescription contract, EndpointAddress address, Boolean wildcard, Boolean useChannelElementKind, ServiceEndpoint& serviceEndpoint)

   at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)

   at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)

   at System.ServiceModel.ConfigurationEndpointTrait`1.CreateSimplexFactory()

   at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait)

   at System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef()

   at QlikViewFileAdmin.MainForm.forcePGOToXMLBut_Click(Object sender, EventArgs e)

   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)

   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)

   at System.Windows.Forms.Control.WndProc(Message& m)

   at System.Windows.Forms.ButtonBase.WndProc(Message& m)

   at System.Windows.Forms.Button.WndProc(Message& m)

   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

QlikViewFileAdmin is the Namespace for my C# Application.

Any assistance would be appreciated. I did also add the ServiceSupport folder and files as shown in the Article.

The QlikViewFileAdmin.ServiceSupport.ServiceKeyBehaviorExtensionElement looks like the following:

using System;

using System.ServiceModel.Configuration;

using System.Configuration;

namespace QlikViewFileAdmin.ServiceSupport

{

public class ServiceKeyBehaviorExtensionElement : BehaviorExtensionElement

{

public override Type BehaviorType

{

get { return typeof(ServiceKeyEndpointBehavior); }

}

protected override object CreateBehavior()

{

return new ServiceKeyEndpointBehavior();

}

}

}

Thank you,

Rick

 
Rick Hoodenpyle


Designated Support Engineer

0 Likes
rhd
Support
Support

I was able to get this to work by rebuilding the application and starting with setting up the API first in order to make sure it worked. Then I added all of my code back in.

0 Likes
Not applicable

Is it possible to dynamically configure the end point on run-time? Let's say i want to build a program which will be able to connect to multiple endpoints without having to individualy  compile them in design time.

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