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
Solved! Go to Solution.
William,
Based on you rest service signature it looks like it is only expecting one input parameter "p_QueryObject" so you input should only contain that.
Hi Robert,
So to pass a JSON as a single parameter, would the following work?
_onSearch: function(){
...
var queryJson = this._buildQueryJSON();
var requestHandle = esriRequest({
url: "rest service URL",
content: {
ppin: "p_QueryObject",
queryJson: queryJson
},
handleAs: "json",
timeout: 10000
},{useProxy: true, usePost: false, disableIdentityLookup: true});
requestHandle.then(lang.hitch(this, this._requestSucceeded), lang.hitch(this, this._requestFailed));
...
},
_buildQueryJSON: function(){
var queryJson = {
neighborhood: this.m_Neighborhood,
schoolDistrict: this.m_SchoolDistrict,
useCodeOne: this.m_UseCodeOne
}
return queryJson;
},
William
William,
It would just be:
content: {
p_QueryObject: the var that contains the data you are passing
}
Hi Robert,
To call a rest service function that takes no parameters, would the following code work?
var requestHandle = esriRequest({
url: "serviceUrl/functionWithNoInputParameters",
handleAs: "json",
timeout: 10000
},{useProxy: true, usePost: false, disableIdentityLookup: true});
requestHandle.then(lang.hitch(this, this._listRequestSucceeded), lang.hitch(this, this._listRequestFailed));
Thank you.
William
Yep that looks good
Hi Drew,
So you think JSON.NET would be better than .NET JavaScriptSerializer?
William
Either JSON.NET or the JavaScriptSerializer will work fine. I can not say what is better for this specific purpose. They will both work.
Hi Drew,
I asked about JavaScriptSerializer because I was having trouble adding JSON.NET to Visual Studio 2010. It kept telling me to update NuGet before adding JSON.NET, but wouldn't let me update NuGet. That was Friday. Today when I tried, I was prompted that there was an update for NuGet, would I like to install it?
Anyway, so far the main function for my rest service looks as follows (in VB.NET).
Function RatioQuery(ByVal p_QueryObject As String) Implements IRatioQueryService.RatioQuery
Dim deserializedSearchParameters As SearchParameters
deserializedSearchParameters = JsonConvert.DeserializeObject(p_QueryObject)
//p_QueryObject = {neighborhood: "MyNeighborhood", schoolDistrict: "MySchoolDistrict", useCodeOne: "MyUseCodeOne"}
End Function
I have a SearchParameters class with the following basic structure.
Public Class SearchParameters
Private m_Neighborhood As String
Private m_SchoolDistrict As String
Private m_UseCode1 As String
Public Property Neighborhood As String
Get
Return m_Neighborhood
End Get
Set(value As String)
m_Neighborhood = value
End Set
End Property
Public Property SchoolDistrict As String
Get
Return m_SchoolDistrict
End Get
Set(value As String)
m_SchoolDistrict = value
End Set
End Property
Public Property UseCode1 As String
Get
Return m_UseCode1
End Get
Set(value As String)
m_UseCode1 = value
End Set
End Property
End Class
How do I set up the constructor for SearchParameters to get the proper values from the JSON in the p_QueryObject string assigned to their corresponding counterparts in SearchParameters?
Thank you.
William
William,
Here is an example signature of one of my RESTfull web services:
<WebGet(UriTemplate:="/searchPersonalProperty?value={val}&by={by}", ResponseFormat:=WebMessageFormat.Json, BodyStyle:=WebMessageBodyStyle.Bare)>
Public Function SearchPP(Optional ByVal val As String = "", Optional ByVal by As String = "") As ppSearchResults
And the JS code to call it:
var requestHandle = esriRequest({
url: 'http://..../searchPersonalProperty',
content: {
value: sValue,
by: byWhich
},
handleAs: "json",
timeout: 10000
}, {
useProxy: false,
usePost: false,
disableIdentityLookup: true
});
Hi Robert,
Are you suggesting I use this format so I can avoid having to deserialize a JSON?
William