How to query a non-ArcGIS database from WAB?

5196
41
Jump to solution
01-12-2017 02:35 PM
WilliamMiller4
Occasional Contributor II

Hi,

I need to send information from my WAB app to a non-ArcGIS database, run a query and return the results back to my app. From what I see online, using only JavaScript is not a secure idea. It looks like I need an intermediary, which my employer would like to be Visual Basic. If someone has successfully done this, please let me know how I might go about it. Any help is appreciated. Thank you for your time.

William

0 Kudos
41 Replies
RobertScheitlin__GISP
MVP Emeritus

William,

   The ASP.net Web API is the easiest route now a days.

0 Kudos
WilliamMiller4
Occasional Contributor II

Hi Robert,

I would definitely go that route, but I only have access to Visual Studio 2010 where I work. Most of the tutorials/examples require 2012 or newer.

William

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Man you are just batting a thousand here.

Try this tutorial then:

How to: Create a Basic WCF Web HTTP Service 

WilliamMiller4
Occasional Contributor II

Hi Robert,

Thank you. This is similar to an example I found on Code Project. Two questions for clarification:

Both have a console application for using the Rest service. I don't need that. I will include similar code in the Web AppBuilder widget to use the Rest service, correct?

So, for the Rest service created using WCF, I should focus on the IService (interface), the Service (class implementing the interface), the webconfig and, according to the Code Project example, an ASAX, right?

William

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Correct

WilliamMiller4
Occasional Contributor II

Hi Robert,

I have a JSON that I want to send to my restful web service. I created it using WCF. I have a class in my service with the same structure as the JSON. How do I have the class constructor read the JSON to create the object so I can use the data?

William

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

William,

   That question has me really scratching my head... With a normal WFS web service you query a DB and create a object and set the return type of the service to be json.

0 Kudos
Drew
by
Occasional Contributor III

I think he is wanting to send JSON data to the web services.
In this case the service sees it as a string and then you can convert it to your object using JSON.NET
Lots of info on google about this
https://www.google.ca/search?q=.net+Convert+JSON+TO+oBJECT&rlz=1C1CHBF_enCA715CA715&oq=.net+Convert+...  

RobertScheitlin__GISP
MVP Emeritus

Thanks Andrew a missed that word send.

        var requestHandle = esriRequest({
          url: 'http://your rest service url',
          content: {
            ppin: ppin,
            f: 'json'
          },
          handleAs: "json",
          timeout: 10000
        },{useProxy: true, usePost: false, disableIdentityLookup: true});
        requestHandle.then(lang.hitch(this, function(taxBillJSON){
.....

Where content is what you are trying to send to the service and ppin is the property name of the input parameter.

WilliamMiller4
Occasional Contributor II

Hi Robert,

If the main function of my rest service has the following format (in VB.NET):

Function RatioQuery(ByVal p_QueryObject As String) Implements IRatioQueryService.RatioQuery
  
End Function

Does the following format for the EsriRequest look okay, with ppin set to "p_QueryObject"?

var requestHandle = esriRequest({
  url: "rest service URL",
  content: {
    ppin: "p_QueryObject",
    neighborhood: this.m_Neighborhood,
    schoolDistrict: this.m_SchoolDistrict,
    useCodeOne: this.m_UseCodeOne
  },
  handleAs: "json",
  timeout: 10000
},{useProxy: true, usePost: false, disableIdentityLookup: true});

requestHandle.then(lang.hitch(this, this._requestSucceeded), lang.hitch(this, this._requestFailed));

Do I need to have f: 'json' in the content object?

Thank you.

William

0 Kudos