Query Portal Tables only

729
8
02-04-2022 10:03 AM
MKa
by
Occasional Contributor III

I am looking to query static table data from my portal at the start of my application.  I don't want to add the data to my map, just get the information from this table to store in memory.  I know how to add these tables to my map, but I really just want to use them as an api for information.  I almost want to simply use them as a webapi of sorts to query information from them when i need it.  I want to hide these table from our users.  I am thinking i need to somehow query against them using my portal credentials and a properly formated URL.  But can seem to get it right.  In catalog here is what my tables and layers that I want to query against look like.  Could someone point me in the right direction?

 

MKa_0-1643997768146.png

 

Tags (1)
0 Kudos
8 Replies
RichRuh
Esri Regular Contributor

Hi MKa,

I assume these portal tables are part of a feature service, right?

Start by creating a connection to the feature service, and then creating a Geodatabase from that connection. You can accomplish this by creating a ServiceConnectionProperties object, and then using the Geodatabase(ServiceConnectionProperties) constructor.

Once you have a Geodatabase, you can open tables and query using OpenDataset and Search.

I hope this helps,

--Rich

0 Kudos
MKa
by
Occasional Contributor III
That is exactly what I am trying to accomplish. I was wondering if
the OpenQueryTable option might be what I am looking for over OpenDataset?
This table represents my worldwide locations, so at any given time, 95% of
this table is unneeded. Much like when i load a layer a set a definition
query. Would the QueryTableDescription improve performance here, in that
the number of results would be far smaller than the OpenDataset.
0 Kudos
RichRuh
Esri Regular Contributor

Calling OpenDataset does not download the contents of the table- just some metadata about the table definition.  The only data that is downloaded are the rows specified by the QueryFilter in Table.Search.

--Rich

0 Kudos
MKa
by
Occasional Contributor III
Is there anyway to query the table in code much like we can do in postman
with a token. But instead use the portal credentials? So in postman I can
query my table like this with a token

https://MYURL/arcgis/sharing/servers/MyServer/rest/services/Company/CompanyWebService/FeatureServer/...'
and GroupCode=099&outFields=*&f=pjson&token=TOKENFROM_AOL

This returns my results using the TOKEN, but in the above I can specify the
query in the initial call. Would this save me time in getting the
information I want at my Configuration startup, or is getting this Table
using my portal instance still the best option. Could this HttpRequest use
my logged in portal credentials instead of the Token?
0 Kudos
RichRuh
Esri Regular Contributor

It's always possible to access Esri REST services such as the feature service outside of the Pro SDK. I'm not familiar with the benefits of that solution, although the integration with Pro would obviously be harder.

0 Kudos
MKa
by
Occasional Contributor III
It takes almost 10 second so initiate the geodatabase from the uri and in
my configuration I need information from these tables right away on
loading. I can’t seem to access the geodatabase until the Loaded stage of
the configuration manager. At that point I then have to wait until the
thread for the geodatabase returns some results. Since I have to load that
gdb at that point and not before application_loaded I am trying to find a
way to get some results with a synchronous web call. Unless you can think
of a way around this so that I can access the gdb before the loaded event.
0 Kudos
MKa
by
Occasional Contributor III

Rich,

I am not trying to do a simple EsriHttpClient query after I verify that my Portal is up and I am signed in.  I have tried every variation of the query using the EsriHttpCient and I cannot get the query to work.  Has anyone else ever run into this or tried to return results in code?  I keep getting the 400 error

"{\"error\":{\"code\":400,\"message\":\"Unable to complete operation.\",\"details\":[\"Unable to perform query operation.\"]}}". 

Here is my latest.  I have tried breaking this up in everyway and this works in postman with a token, but in my code I don't need the token because I am using the EsriHttpClient

EsriHttpClient client = new EsriHttpClient();

string path = "https://MYServer/arcgis/sharing/servers/59621f9802e04755b9a872c25fcfb7ef/rest/services/MyWebService/...";
string query = string.Format("query?{0}&f=json&outFields=*&returnGeometry=true&returnIdsOnly=false", "where=PlantCode='ABC1' and Code='010'");
EsriHttpResponseMessage searchResponse = client.Get(path + query);
HttpContent content = searchResponse.Content;

string response = await content.ReadAsStringAsync();
dynamic resultItems = JObject.Parse(response);

0 Kudos
MKa
by
Occasional Contributor III

I have been using fiddler and it looks like the EsriHttpClient is doing something to my above where clause

THIS code from above

string query = string.Format("query?{0}&f=json&outFields=*&returnGeometry=true&returnIdsOnly=false", "where=PlantCode='ABC1' and Code='010'");
EsriHttpResponseMessage searchResponse = client.Get(path + query);
HttpContent content = searchResponse.Content;

Should send this URI

"query?where=PlantCode='ABC1' and Code='010'&f=json&outFields=*&returnGeometry=true&returnIdsOnly=false"

But instead, fiddler shows this going through

"query?where=PlantCode&f=json&outFields=*&returnGeometry=true&returnIdsOnly=false"

Notice how after the PlantCode the equals sign is cuttoff?  How do i tell the EsriHttpRequest to ignore that and not do that.  This works in Postman, so I know it has to be possible.

0 Kudos