ArcGIS Runtime for web application?

1208
8
03-24-2020 12:01 PM
PeterParker4
New Contributor

Is using the Runtime for a web-based (not desktop) application a valid use of it? I want to contact ESRI services via the API and use within our web application.

Thanks,

Peter

0 Kudos
8 Replies
MichaelBranscomb
Esri Frequent Contributor

Hi,

ArcGIS Runtime SDK for .NET is not supported for use in web applications or web services.

For building client web apps see ArcGIS API for JavaScript | ArcGIS for Developers (Latest)  and for developing Enterprise services see ArcGIS Enterprise SDK.

Thanks

Mike 

PeterParker4
New Contributor

Thank you for the quick reply. Just to verify, I want to be able to connect to an ESRI feature service, query it and then return value added information back to my web application via JSON and that should be possible with this API, yes?

0 Kudos
JoeHershman
MVP Regular Contributor

For a server side application you could use the Rest API.  Could do this through python, a C# service.  Or you could use a ArcGIS Server SOE.

PeterParker4
New Contributor

Thanks Joe. So by the term "Rest API" do you mean going directly to the ArcServer and calling the REST endpoint directly? Or is there an Nuget Package that provides that functionality? The Runtime seemed to be what I was after but oriented towards a desktop environment...

0 Kudos
JoeHershman
MVP Regular Contributor

If you wanted to go down the C# route and create a service then yes you would need to make calls directly to the Rest API.  Using python you could use the ArcGIS API for Python | ArcGIS for Developers.

As Mike said, though, you can use the Javascript API and that gives high level language access to the Rest API similar to what Runtime gives from a WPF or Mobile application.  From a web page, this would seem to me to be the best approach, I was just offering up alternatives if for some reason you wanted a different approach

PeterParker4
New Contributor

I appreciate it Joe. We do want to be able to access via the server/C# side as that is where we will maintain metadata about different sources of query-able data whether an ESRI feature server or something else.

I just wanted to make sure there wasn't something I could take advantage of and elevate inventing the wheel. 

0 Kudos
JoeHershman
MVP Regular Contributor

Fortunately creating a Rest Service in asp.net core is incredibly straight forward, VS gives a template that will generate the framework with an example Controller.

One of the main issues in setting up using the Rest API with secure Portal services is you need to create a ArcGISHttpClientHandler

// _portalManager is a service to mange my portal connections
ArcGISHttpClientHandler handler = new ArcGISHttpClientHandler { ArcGISCredential = await _portalManager.Credential(true) };

using var client = new HttpClient(handler);‍‍‍

An operation that does a standard http get:

var featureServiceUrl = new Uri($"{FeatureServiceUrl(replicaDefinition)}?f=json");

//confirm can connect to Url
var _ = await client.GetStringAsync(featureServiceUrl);

A post is a little more involved but still pretty straight forward:

var parameters = new Dictionary<string, string>
{
	{"f", "json"},
	{"async", "true"},
	{"dataFormat", "sqlite"},
	{"replicaID", replicaDefinition.ReplicaId.ToLower()},
	{"rollbackOnFailure", "false"},
	{"syncLayers", await GetSyncLayersAsync(replicaDefinition)},
	{"transportType", "esriTransportTypeUrl"}
};

var content = new FormUrlEncodedContent(parameters);
	
var response = await client.PostAsync(requestUri, content);

if ( !(response.Content is ByteArrayContent byteArrayContent) ) return null;

var json = await byteArrayContent.ReadAsStringAsync();

var status = JsonConvert.DeserializeObject<StatusResponse>(json);

Good luck

PeterParker4
New Contributor

Thanks Joe, that will be very helpful moving forward.

Peter

0 Kudos