1

The issue I am having connecting to a service via PowerShell, versus using C#, is that the service is expecting a key passed in the header.

I can use new-WebServiceProxy with the URI and have it pass the default credentials. I can then get the time-limited service key, but for subsequent calls to the service, there is no way to pass the key, which results in an error that there is no valid service key.

I know the cmdlet uses the System.Net.WebClient class and that had a settable headers property that I want to try using. I just can't seem to get that class to behave the same way as the cmdlet and return an object. Does anyone know how?

This is what I am using but which to implement in .Net directly from PowerShell:

$QMSService = New-WebServiceProxy -Uri http://localhost:4799/QMS/Service -Namespace QlikViewServer -UseDefaultCredential

That is the Powershell cmdlet I use to access the service. I would like to accomplish the same using:

$Client = New-Object System.Net.WebClient
$Client.UseDefaultCredentials = $true
$Client.BaseAddress = "http://localhost:4799/QMS/Service"

I just can't figure out how to create a proxy object that gives me access to all the members the service provides, using System.Net.WebClient. Once I set that, I can grab the TimeLimitedServiceKey and do this:

$ServiceKey = $ProxyObjectCreatedFromClient.GetTimeLimitedServiceKey()
$Client.Headers = "X-Service-Key", $ServiceKey

If someone could please help me on how to create the Proxy Object.

user3377627
  • 363
  • 3
  • 7
  • 22

1 Answers1

0

It appears that the GetTimeLimitedServiceKey() method is from the QMSClient API: https://help.qlik.com/en-US/qlikview-developer/12.1/apis/QMS%20API/html/2be1e405-a7e5-4a43-b1b6-9540b23a6226.htm

...meaning, you'll need to reference that third-party API directly (New-Object, Add-Type, Add-Type w/p/invoke, etc.) and then make the call to GetTimeLimitedServiceKey()

$service = New-WebServiceProxy -Uri http://someHost:4799/QMS/Service -Namespace QlikViewServer -Credential (get-credential)
$serviceKey = $service.GetTimeLimitedServiceKey()

https://community.qlik.com/thread/143003

thepip3r
  • 2,855
  • 6
  • 32
  • 38
  • It's a web service, so creating a proxy object using new-webserviceproxy simply keeps an open connection to the service itself, but generates an object for me to use, giving me access to said service's methods. I can get the key via that object but, that cmdlet does not allow me to inject header info to my post calls to the uri. The .net equivalent does, but I can't figure out for the life of me, how to generate a proxy object that gives me access to the methods the PS cmdlet does. – user3377627 Jun 07 '17 at 17:31
  • Isn't $QMSService just the entry point? Have you tried $QMSService | gm? to see what properties/methods are available? – thepip3r Jun 07 '17 at 17:52
  • I'm just trying to figure out, how I can get a proxy object, just like what new-webserviceproxy returns, but using system.net.webclient. I tried doing a gm on the object returned from system.net.webclient, but I don't see any method that returns such an object. – user3377627 Jun 07 '17 at 20:22
  • The problem is that the only "proxy" named object in .NET is a proxy like a n 80/443 website filtering proxy. The proxy used in the context you are (a web service provider for persistent localized calls to a remote API) doesn't exist in the same context outside of that single cmdlet. The examples I found of the qlik API. See edited answer for example of using hte cmdlet over the non-persistent call to .NET webclient. – thepip3r Jun 08 '17 at 13:43