West Wind Internet and Client Tools
Consuming ASP.NET Web API Servers from VFP app
Gravatar is a globally recognized avatar based on your email address. Consuming ASP.NET Web API Servers from VFP app
  Dmitry Litvak
  All
  Dec 18, 2016 @ 09:48am

Hello,

I hope I selected the right forum for my questions.

I need to be able to consume (or call, whichever is the right term) ASP.NET Web API service(s) from a VFP 9 application. The Web API was developed by a 3P.

What I know about their service is as follows:

The API uses OAuth 2.0 protocol for client authentication. OWIN framework is integrated into project for this purpose. For interacting with the API, client app should receive a special access_token from the OWIN framework and pass it in headers in every API request. The following request allows generating a new token: • REQUEST Method: POST Url: /token Body: username=5000&grant_type=password&password=ABC123

Is West Wind Client Tools what I need to incorporate in my VFP 9 app to call this Web API? Is there an example I can look at for this?

TIA Dmitry Litvak

Gravatar is a globally recognized avatar based on your email address. re: Consuming ASP.NET Web API Servers from VFP app
  Rick Strahl
  Dmitry Litvak
  Dec 18, 2016 @ 06:49pm

Yes you can use West Wind Client Tools for this. Specifically you might be able to use the wwJsonServiceClient class which lets you wrap REST services with FoxPro methods that call the REST methods.

Calling a service with oAuth tokens involves retrieving a token and then adding the token to the headers you send. What that looks like depends on the oAuth implementation used - there's no generic way to do this. Usually an API provides some sort of endpoint to retrieve the the token and the token is then provided on each request as a header typically (Authorization: Bearer <token here>).

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Consuming ASP.NET Web API Servers from VFP app
  Dmitry Litvak
  Rick Strahl
  Dec 19, 2016 @ 08:19am

UPDATE: Resolved.

Hi again,

I am learing the The WW Client Tools, based on the shareware copy.

When I use your example 1 in the article http://www.west-wind.com/wconnect/weblog/ShowEntry.blog?id=920

loAlbums = loProxy.CallService("http://albumviewerswf.west-wind.com/api/albums","","GET")

Where you have the code getting the loAlbums, I get error

" Unable to load wwDotNetBridge: " + this.ErrorMsg

This error is in this segement of INIT of wwDotNetBridge class:

*** Fail creation if the object couldn't be created IF ISNULL(this.Load()) ERROR "Unable to load wwDotNetBridge: " + this.cErrorMsg RETURN .F. ENDIF

What am I missing? Thank you.

UPDATE: I found that the problem happens on the line ClrCreateInstanceFrom below:

```text
lcError = SPACE(2048)
	lnSize = 0
	lnDispHandle = ClrCreateInstanceFrom(FULLPATH("wwDotNetBridge.dll"),;
			"Westwind.WebConnection.wwDotNetBridge",@lcError,@lnSize)

The error is '0x80131515', could not load assembly.

And the wwDotNetBridge.dll is in the folder where the code is being executed.
© 1996-2025