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.