1. ATK Gimmy Susan
  2. SnapObjects
  3. Wednesday, 5 June 2019 14:46 PM UTC
Good morning

I'm running the tutorial: "Create a Web API" I state that I don't have the SQLServer database and I'm adapting the code for an oralce database. Question: In the end the first part says: [cit]
The following JSON is returned: {"departmentId": 1, "name": "Engineering", "groupName": "Research and Development", "modifiedDate": "2008-04-30T00: 00: 00"} [end cit]
How does it know which table to read from?

ty

Accepted Answer
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Wednesday, 5 June 2019 22:25 PM UTC
  2. SnapObjects
  3. # Permalink

Hi Gimme, I now also understand your question, which now has already been answered by Govinda Lopez.

To be honest, I was having exactly the same question when I was trying out the web api.

 

You might already know, but just in case you don't: I found my answers by using the menu:

Edit > Find & Replace > Find in files (or better: ctrl+F)

Then specify under "Look in": Entire solution.

So I searched on "DepartmentId" to find it was defined in the SampleService1Model.cs file.

That's how I find anything anywhere and find it very useful for a noob like me.

 

HIH.

Comment
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Wednesday, 5 June 2019 15:18 PM UTC
  2. SnapObjects
  3. # 1

Probably uses a DataWindow and the ExportJSON method.

Comment
  1. ATK Gimmy Susan
  2. Wednesday, 5 June 2019 15:51 PM UTC
It does not seem.

The powerbuilder client part uses a data window, but the server part does not.

The server part returns a jason, but I don't understand how.



https://www.appeon.com/support/documents/appeon_online_help/snapdevelop2019/Create_a_Web_API/index.html



= (
  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Wednesday, 5 June 2019 16:13 PM UTC
  2. SnapObjects
  3. # 2

If you followed the naming of the example:

 

Do you have :

using SnapObjects.Data.Oracle;

in DefaultDataContext1.cs ?

 

Do you have:

using SnapObjects.Data.Oracle;

in startup.cs?

 

and ..:

// Uncomment the following line to connect to the Oracle database.
            // Note: Replace "ContextName" with the configured context name; replace "key" with the database connection //name that exists in appsettings.json. The sample code is as follows:
services.AddDataContext(m => m.UseOracle(Configuration["ConnectionStrings:R1"]));

?

R1 is the name of my connection profile, you can find it in the "appsettings.json" file:

"AllowedHosts": "*",
  "ConnectionStrings": {
    "R1": "POOLING=True;ENLIST=true;USER ID=...;DATA SOURCE=\"(DESCRIPTION=(ADDRESS=(HOST=...)(PORT=1521)(PROTOCOL=Tcp))(CONNECT_DATA=(SERVICE_NAME=...)))\";CONNECTION TIMEOUT=15;STATEMENT CACHE SIZE=0;PROMOTABLE TRANSACTION=promotable;PERSIST SECURITY INFO=False;CONNECTION LIFETIME=0;METADATA POOLING=True;LOAD BALANCING=False;STATEMENT CACHE PURGE=False;PASSWORD=...;VALIDATE CONNECTION=False;MIN POOL SIZE=1;MAX POOL SIZE=100;INCR POOL SIZE=5;HA EVENTS=False"
  }

HIH

Comment
There are no comments made yet.
Armeen Mazda @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 5 June 2019 17:23 PM UTC
  2. SnapObjects
  3. # 3

Miguel is correct that your project needs the SnapObjects.Data.Oracle to connect to Oracle database.  And just to clarify,  the way the service knows what database to connect to is based on the data context that you create. 

This tutorial you pointed out to is using the SqlModelMapper object.  I would recommend to first start with the .NET DataStore since you have strong PowerBuilder background.  https://www.appeon.com/support/documents/appeon_online_help/powerbuilder/CRUD_Operations_with_.NET_DataStore/index.html

Comment
  1. ATK Gimmy Susan
  2. Wednesday, 5 June 2019 18:38 PM UTC
Hi Armeen



How are you ?

As you can see I'm playing with the new features.

=)



Going back to my problem.

The changes to be made to connect to Oracle are quite clear. And I made them.



The question is much simpler.

Where do you find the program data?



* In the first test: ["Value1", "value2"]

* In the second test: {"DepartmentId": 1, "name": "Engineering", "groupName": "Research and development", "modifiedDate": "2008-04-30T00: 00: 00"}





I do not see references to any table.



TY
  1. Helpful
There are no comments made yet.
Govinda Lopez @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 5 June 2019 20:45 PM UTC
  2. SnapObjects
  3. # 4

Hi,

 

I see what you mean. The SampleService1 is calling the SampleService1Model. The model is the one that actually maps the table(s) from the database. You can look into this tutorial: https://www.appeon.com/support/documents/appeon_online_help/powerbuilder/CRUD_Operations_with_.NET_DataStore/index.html for a deeper example on how to do it.

Thank you for pointing this out to us. We will update this tutorial to show the code of that service and model. 

Answering to your other question: Why does it return JSON? In PB, you can tell the RESTClient object to request "application/json" by applying this value to the "Content-type" header of the request.

lnv_RESTClient.SetRequestHeader("Content-type", "application/json")

That's how the Web API know's to return a JSON.

 

 

Regards,

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.