OnCommand Storage Management Software Discussions

Calling a WFA Workflow Using Rest over HTTPS

Hello Guys,

 

I am new to the Workflow Rest API. all seems to be working weel when i write the code in powershell and execute.

 

but then i put the same code on Workflow command it gives me the below error:

 

"The underlying connection was closed: An unexpected error occurred on a send."

 

I am plaving the below lines in the code to work with SSL/TLS, and as i mentioned it works well with simple Powershell Script, but not though Workflow engine. specially when using HTTPS connection. Http connection is no problems.

 

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;

 

I am also attaching the workflow which calls another workflow with this post.

 

Any possible support suggestations would help me taking it further.

 

,Sheelnidhi

4 REPLIES 4

Re: Calling a WFA Workflow Using Rest over HTTPS

Are you sure you do not have any troubles related to WFA using a self-signed certificate?

Re: Calling a WFA Workflow Using Rest over HTTPS

Nops, i dont have any issues with Self Signed Certificates. as i can easily open the HTTPS page and also able to execute the Workflow using REST API using powershell CLI.

but i get this error then i put the same powershell command in WFA.

 

,Sheelnidhi

Highlighted

Re: Calling a WFA Workflow Using Rest over HTTPS

Are you providing credentials in the header of the REST call via PowerShell? If not, you'll need to add that. One way to do that is with a base64 encoded encoded Basic Authorization header like this example.

 

# Create base64 encoded credential
$mycred = Get-Credential
$EncodedAuthorization = [System.Text.Encoding]::UTF8.GetBytes($mycred.username + ':' + $mycred.GetNetworkCredential().password)
$EncodedPassword = [System.Convert]::ToBase64String($EncodedAuthorization)
$Headers = @{"Authorization"="Basic $($EncodedPassword)"}

 

Use the created $Headers in the call to the workflow vie Invoke-WebRequest or Invoke-RestMethod

 

Invoke-WebRequest -Method GET -Uri $URi -Headers $Headers 
Invoke-RestMethod -Method GET -Uri $URi -Headers $Headers 

Re: Calling a WFA Workflow Using Rest over HTTPS

Hello,

 

I did some more powershell and it seems that i have found a way, added the below code:

 

[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;

add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

 


function Get-BasicAuthCreds {
param([string]$Username,[string]$Password)
$AuthString = "{0}:{1}" -f $Username,$Password
$AuthBytes = [System.Text.Encoding]::Ascii.GetBytes($AuthString)
return [Convert]::ToBase64String($AuthBytes)
}
$BasicCreds = Get-BasicAuthCreds -Username $user -Password $pass
$credential = New-Object System.Management.Automation.PSCredential ($user, (ConvertTo-SecureString $pass -AsPlainText -Force))

 

 

,Sheelnidhi

Forums