WooCommerce Integration

WooCommerce Integration

  

I'm trying to create an integration with the WooCommerce REST API. I am using the WoocommerceNET library in a custom extension.

This library makes use of Tasks in .NET: 


Task<List<Product>> task = wc.GetProducts(parameters);
task.Wait();
List<Product> products = task.Result;


This works fine if I run it from Visual Studio through a Unit Test class:

[TestMethod]
        public void TestMethod1()
        {
            CssWooCommerce wc = new CssWooCommerce();

            string URL = "http://my.shop.com/wp-json/wc/v1/";
            string key = "1234567890";
            string secret = "1234567890";

            RLParameterRecordList parameters = new RLParameterRecordList();

            RLProductRecordList products = new RLProductRecordList();

            wc.MssGetProducts(URL, key, secret, parameters, out products);

            Debug.WriteLine("Retrieved " + products.Count + " products");
        }

This returns the following in the debug output window:

Retrieved 10 products
The thread 0x6a8 has exited with code 0 (0x0).


However when I want to use the extension in the Outsystems Studio environment I get a Thread was being aborted message:


Id:604c16d7-7f6a-43ec-a786-ec8c2b71b6d1
Time of Log:2017-01-11 23:33:34
eSpace:WooIntegration
Tenant:Users
User: (2)
Session Id:0z1pgdso0a5acwui1qbkk1dy
Server:S1OQH-LT2DYI
Module:Extension metho
Message:Thread was being aborted.
Environment InformationeSpaceVer: 10 (Id=48, PubId=49, CompiledWith=10.0.200.2)
RequestUrl: https://backoffice.outsystemscloud.com/WooIntegration/Products.aspx?_ts=1484177487935 (Method: POST)
AppDomain: /LM/W3SVC/88/ROOT/WooIntegration-28-131286510638667697
FilePath: C:\OutSystems\Sandboxes\IYDPTK034\Platform Server\running\WooIntegration\Products.aspx
ClientIp: 212.123.150.48
Locale: en-US
DateFormat: yyyy-MM-dd
PID: 14124 ('w3wp', Started='1/3/2017 4:50:45 AM', Priv=444Mb, Virt=18073Mb)
TID: 144
Thread Name:
.NET: 4.0.30319.42000
Stack:Thread was being aborted.
   at System.Threading.Monitor.ObjWait(Boolean exitContext, Int32 millisecondsTimeout, Object obj)
   at System.Threading.ManualResetEventSlim.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.SpinThenBlockingWait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.InternalWait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at OutSystems.NssWooCommerce.CssWooCommerce.MssGetProducts(String ssURL, String ssKey, String ssSecret, RLParameterRecordList ssParameters, RLProductRecordList& ssProducts)
   at ssWooIntegration.RssExtensionWooCommerce.MssGetProducts(HeContext heContext, String inParamURL, String inParamKey, String inParamSecret, RecordList inParamParameters, RecordList& outParamProducts)



I cannot figure out why this thread times out in the Outsystems environment, but not when I run it from Visual Studio. Can anyone help me with this? Or should I do this in another way?


Hello Joris,

Just to make sure I understand what's happening: You make the request to the WooCommerce server, the request gets blocked, and then this error occurs. Is that it?

Also, any particular reason for using an extension instead of the REST capabilities in OutSystems?

Cheers,
R

Hi Rodrigo, I'm not sure what exactly is happening in the outsystems server. That is why I am posting on this forum. If I try from Visual Studio the custom code works perfectly, but when I run from Outsystems I get the error message. I suppose it has something to do with the task.Wait() statement in the code because the error says that a 'Thread has been aborted'.

I am using an extension that calls a DLL because the service I want to use (WooCommerce REST) uses OAuth 1.0a authentication that I think is not supported by the REST capabilities in OutSystems. The WooCommerceNET library handles this authentication perfectly but it uses separate threads for calling the service.

Hello Joris,

Sorry, I wasn't clear in my question. What I wanted to know was if the request got blocked on the browser and the error was issued because of a timeout, or if the request returns immediately and the thread is aborted right after the browser gets the response.

If you're stuck on the browser while the request is being made and there's a timeout, it may be related to access problems to the WooCommerce server. If the request returns immediately and you get this error, it may be related to synchronization issues on the library you're using.

Cheers,

Also, looking at the API documentation, you can probably use our REST capabilities together with the basic authentication method. Set "Username" to consumer_key and "Password" to consumer_secret.

Cheers,
R