You are viewing limited content. For full access, please sign in.

Question

Question

Script Activity REST requests return null

asked on January 3, 2019

I have a Script activity that tries to connect to an endpoint with HTTPS with some information then returns a response in JSON.

 

I can get into the finer details if the answer to this is no, but before that, I'm wondering if there is any reason why I wouldn't be able to do this through a Workflow script activity. The code works perfectly fine in Visual Studio, but when running through Workflow it always returns "null," so I'm wondering if it is some sort of limitation of Workflow regarding HTTPS or REST. I did try on multiple servers, but each time through Workflow it returned "null."

0 0

Answer

SELECTED ANSWER
replied on January 8, 2019

The TLS configuration for applications using .Net 4 is described in this KB article.

1 0

Replies

replied on January 3, 2019

A script activity should work fine for what you are trying to do. Alternatively, you could try the HTTP request activity to make the request. 

I would need to know the specific 'it' that is returning null to help you further. Can you post the code that you are using (sensitive information redacted) to actually make the web request?

0 0
replied on January 4, 2019

The entire code can be found at https://github.com/CardConnect/csharp-cardconnect-api/blob/master/CardConnectRestClientExample.cs. It will not work without credentials that we have, a proper endpoint, and some of the JSON information changed, but all I am asking about is the first line of Main. The authTransaction() method works perfectly fine in VisualStudio but will not work through Workflow.

 

In VS the "response" variable in line 101 is a JSON array. In Workflow it is null, so the foreach in line 103 throws an error:

 

Object reference not set to an instance of an object.
---Stack Trace---

   at WorkflowActivity.Scripting.Script.Program.authTransaction()
   at WorkflowActivity.Scripting.Script.Program.Main(String[] args)
   at WorkflowActivity.Scripting.ScriptBase.ExecuteScript(ScriptExecutionContext context)

***

I don't think I would speak to them about this, because the code works outside of Workflow, so I don't think it's an issue with the code itself.

 

I ran it like this in Workflow:

 

/*Copyright 2014, CardConnect (http://www.cardconnect.com)

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.*/

namespace WorkflowActivity.Scripting.Script
{
    using RestSharp;
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;
    using Newtonsoft.Json.Linq;
    using Newtonsoft.Json;

    /// <summary>
    /// Provides one or more methods that can be run when the workflow scripting activity is performed.
    /// </summary>
    public class Script1 : ScriptClass90
    {
        /// <summary>
        /// This method is run when the activity is performed.
        /// </summary>
        protected override void Execute()
        {
            Program.Main(null);
        }
    }

    class Program
    {
        private static String ENDPOINT = (our endpoint);
        private static String USERNAME = (our username);
        private static String PASSWORD = (our password);

        public static void Main(String[] args)
        {

et cetera. Is it an issue with the way I ran it?

 

Thank you

0 0
replied on January 4, 2019

While I think you could run it more directly without copying the Program class and Main method, there are two things that I see here. 

First, they reference both Newtonsoft.Json and something called RestSharp. I'd make sure these are in the GAC of your workflow server machine. If I had to take a guess, it's probably the RestSharp reference.

Second, you may need to reach out to them because if you look at https://github.com/CardConnect/csharp-cardconnect-api/blob/master/CardConnectRestClient.cs, you can see on line 255 that it returns null in the presence of a json reader error instead of actually telling the client (you) the actual error. Without the actual error we'll basically be just guessing at the issue.

 

 

0 0
replied on January 4, 2019

Both of those references are being done through dlls that are in the user's Documents folder on the machine. I did it the same way through Visual Studio and it worked there.

 

Additionally, the code is not hitting that JsonReader error. If I comment out the try-catch block and replace it with

 

return "hello";

 

Then I get an error about trying to cast a String to a JObject.

 

If I uncomment the try-catch and put that return "hello" in the catch block, that String cast error does not occur, therefore it isn't hitting the catch block.

0 0
replied on January 4, 2019

To give an update, it appears that if I compile it as an exe and try to run it on another computer that way, it doesn't work, giving an error that "The request was aborted: Could not create SSL/TLS secure channel." Since this happens even when Workflow isn't involved at all, I don't think this is a Laserfiche error. I just have to figure out why we get that error on our development server and my coworkers' computers but not mine, where it works fine.

 

Thank you for your attempts to assist.

0 0
replied on January 4, 2019

What version of .Net do you have installed on WF Server?

Does the WF Server have the same certificates as your dev machine? Sometimes that error can indicate it could not validate the certificate for the web service.

0 0
replied on January 7, 2019

My PC has 4.7.2 and the WF Server has 4.6.2.

 

My PC has 3 expired certificates as well as one for NVIDIA GameStream Server, and two WMSvc-SHA2 certificates. The WF server has one certificate that my coworker generated as a test for this. The Signature algorithm says sha256RSA which is what the two WMSvc-SHA2 ones say as well.

0 0
replied on January 7, 2019

I was pointed to a registry key at Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\.NETFramework\v4.0.30319 called "SchUseStrongCrypto" that was on my PC (set to 1) but not present on my coworkers' PCs or the Workflow server. After adding that key to the WF server and setting it to 1, I am able to run the script as an .exe file on the WF server.

However, when I try to run it through WF as a script, it throws the same error as before in the same place.

0 0
SELECTED ANSWER
replied on January 8, 2019

The TLS configuration for applications using .Net 4 is described in this KB article.

1 0
replied on January 8, 2019

Thank you very much! After performing those regedit steps, the request went through correctly.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.