West Wind Internet and Client Tools
Can not load file or assembly newtonsoft.json
Gravatar is a globally recognized avatar based on your email address. Can not load file or assembly newtonsoft.json
  VFPJCOOK
  All
  Jul 9, 2020 @ 02:11pm

I am trying to access a JSON REST service. I have a license for so I decided to try using my West Wind Internet and Client tools. I read what I can find and understand and wrote the following code:

loProxy = CREATEOBJECT("wwJsonServiceClient")

*** Create custom Http Object for Authentication
loHttp = loProxy.CreatewwHttp()

*** Now make customization to the HTTP object
loHttp.cUsername = "ChatakPrepaidAdminBasicAuth"
loHttp.cPassword = "ChatakAdmin@Secure"
loHttp.AddHeader("Content-Type","application/json")
loHttp.AddHeader("Authorization","Basic Q2hhdGFrUHJlcGFpZEFkbWluQmFzaWNBdXR")


*** Proxy will use this loHttp instance internally
loResponse = loProxy.CallService("https://qa-ci.rapidefund.com:9014/prepaidservices/secure/oauth/token?grant_type=password&username=ChatakPrepaidAdminUser&password=ChatakPrepaidAdminPass","","GET")

I get the following error on the call to CallService:

I included wwhttp.prg in my project. it is dated 5/8/17.

I included wwjasonserializer.prg in my project. it is dated 10/10/17.

wwdotnetbridge.dll is in the home directory for my program and is dated 10/13/18.

wwipstuff.dll is in the home directory for my program and is dated 10/20/17.

newtonsoft.json.dll is in the home directory for my program and is dated 6/18/17.

Can you tell me what is causing the error?

Thanks, John

Gravatar is a globally recognized avatar based on your email address. re: Can not load file or assembly newtonsoft.json
  Rick Strahl
  VFPJCOOK
  Jul 10, 2020 @ 01:15pm

Probably a version mismatch.

First make sure you're using the right combination of libraries of wwDotnetBridge.dll and newtonsoft.json.dll from the same version of Client Tools or Web Connection. If you're just using internal features than that should just work.

If you have other .NET dependencies that are also using newtonsoft json then they might be using a different version of it and that can cause problems. If that's the case you need to explicitly specify which version of the assembly .NET should use via a exe.confg file setting:

Controlling the JSON.NET Version in wwDotnetBridge with Assembly Versions

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Can not load file or assembly newtonsoft.json
  VFPJCOOK
  Rick Strahl
  Jul 12, 2020 @ 08:49am

Hi Rick, Thanks. I had read the doc about doing that and had tried creating the vfp9.exe.config. Did not have any luck with that. Anyway, I decided to use the latest wwdotnetbridge.dll and newtonsoft.json.dll from my recent upgrade of wwconnect. That worked.

The call to the service that I described in my previous post was to get a token that I have to use in subsequent calls to the service. I have that token and am ready to make my next call to the service. I am confused about how to pass the value for the data parameter (the 2nd parameter) to the CallService routine.

When I do this using Postman, it works. The Body for the PUT on Postman looks like this:

{
"clientId": "GFGD84KJBAPDMZKSTDG4281216564627832RAPIDGENERAL",
"agentAccountNumber": "1000000191",
"agentANI": "1234567891",
"txnAmount": "20.00",
"activateFlag": "true",
"txnDescription": "Load Amount of $20.00",
"clientTransId": "1111111111111111",
"cardHolderId": "Cardholder",
"requestKey":"ACCOUNT_NUMBER",
"requestValue": "70000468499",
"optedForCard": "true",
"acceptedTermsAndConditions": "true",
"cardDetails":
{
"firstName": "JOSEPH",
"lastName": "AARON",
"dateOfBirth": "01/01/1990",
"mobileNumber":"4355353454",
"email":"none@rpdfin.com",
"address1": "123 Street",
"address2": "",
"city": "City",
"state": "UT",
"zip": "12345",
"country": "US"
}
}

Notice the parameters clientId thru acceptedTermsAndConditions are strings but cardDetails is an object and then it has properties firstName thru country.

Looking at some of your samples I tried this:

loData = CREATEOBJECT("Empty")
ADDPROPERTY(loData,"clientId","GFGD84KJBAPDMZKSTDG4281216564627832RAPIDGENERAL")
ADDPROPERTY(loData,"agentAccountNumber","1000000191")
ADDPROPERTY(loData,"agentANI","1234567891")
ADDPROPERTY(loData,"txnAmount","20.00")
ADDPROPERTY(loData,"activateFlag","true")
ADDPROPERTY(loData,"txnDescription","Load Amount of $20.00")
ADDPROPERTY(loData,"clientTransId", "2222222222222222")
ADDPROPERTY(loData,"cardHolderId","Cardholder")
ADDPROPERTY(loData,"requestKey","ACCOUNT_NUMBER")
ADDPROPERTY(loData,"requestValue","70000468500")
ADDPROPERTY(loData,"optedForCard","true")
ADDPROPERTY(loData,"acceptedTermsAndConditions","true")
ADDPROPERTY(loData,"CardDetails","")
ADDPROPERTY(loData.CardDetails,"firstName","JOSEPH")
ADDPROPERTY(loData.CardDetails,"lastName","AARON")
ADDPROPERTY(loData.CardDetails,"dateOfBirth","01/01/1990")
ADDPROPERTY(loData.CardDetails,"mobileNumber","4355353454")
ADDPROPERTY(loData.CardDetails,"email","none@rpdfin.com")
ADDPROPERTY(loData.CardDetails,"address1","123 Street")
ADDPROPERTY(loData.CardDetails,"address2","")
ADDPROPERTY(loData.CardDetails,"city","City")
ADDPROPERTY(loData.CardDetails,"state","UT")
ADDPROPERTY(loData.CardDetails,"zip","12345")
ADDPROPERTY(loData.CardDetails,"country","US")

I was just guessing but as I am sure you know, FoxPro is giving me errors on the loData.CardDetails lines. So, how would I build the value for loData so that I can make the following call to the service:

loResponse = loProxy.CallService("https://qa-ci.rapidefund.com:9014/prepaidservices/rest/external-bulk-cards/nokyc/loadAmountAndEnroll",loData,"POST")

Thanks, John

Gravatar is a globally recognized avatar based on your email address. re: Can not load file or assembly newtonsoft.json
  Mike McDonald
  VFPJCOOK
  Jul 12, 2020 @ 10:18am

>..FoxPro is giving me errors on the loData.CardDetails lines.

Instead of ..

ADDPROPERTY(loData,"CardDetails","")

.. you want to do ..

loCard = CREATEOBJECT("empty")
ADDPROPERTY(loData,"CardDetails",loCard)

This creates a 'CardDetails' property of loData which is an object, not a string. Then you can assign new properties to that object.

- Mike McDonald
Software Design of Kentucky

Gravatar is a globally recognized avatar based on your email address. re: Gathering an object in CallbackHandler
  Rick Strahl
  Mike McDonald
  Jul 12, 2020 @ 09:57pm

Most likely it's because you're sending everything lowercase and the server expects proper case objects. JSON is case sensitive and FoxPro can't easily do that. Certainly not with AddProperty.

There are a number of ways you can work around this:

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Can not load file or assembly newtonsoft.json
  VFPJCOOK
  Mike McDonald
  Jul 13, 2020 @ 02:10pm

Mike, That was the issue. I sort of knew it was somewhat a "conceptual" issue meaning more foxpro than Rick's tools. So, I learned something really good today. Thanks, John

Gravatar is a globally recognized avatar based on your email address. re: Gathering an object in CallbackHandler
  VFPJCOOK
  Rick Strahl
  Jul 13, 2020 @ 02:15pm

Hi Rick, Yes, after applying what Mike told me, I ran into the case sensitive issue and used the PropertyNamesOverride to fix. It all worked and I have successfully called the service to do one of the things I need it to do. I have some more calls to different functions of their service but this is really easy compared to calling SOAP based services. I've learned a lot and the tools are GREAT!

Thanks, John

Gravatar is a globally recognized avatar based on your email address. re: Gathering an object in CallbackHandler
  Rick Strahl
  VFPJCOOK
  Jul 13, 2020 @ 02:24pm

I would recommend using the loSerializer.Property() method to add properties. This sets OverridePropertyNames automatically as you make the property assignments and you're calling AddProperty() anyway - same syntax, just a different way to call it.

+++ Rick ---

© 1996-2024