Sunday, November 1, 2009

Using the ArcGIS Server REST API in .NET applications

Over the past year I've handled a number of questions regarding the use the ArcGIS Server REST API in a .NET application. It can be done quite effectively, but isn't explicitly promoted by ESRI since the REST API is primarily designed to be consumed by pre-packaged Web clients like the ArcGIS JavaScript, Flex, and Silverlight/WPF APIs. However, using REST programmatically in a .NET application context without installing an ESRI product can make for some powerful and focused yet lightweight solutions. In addition, if you need to do something relatively simple you don't have to generate a load of client-side proxy classes like you do with SOAP.

I've included a simple code example below to highlight how easy it is to integrate ArcGIS Server services via REST in your .NET app. The example uses an ArcGIS Online geocode service to geocode an address and return a location.

Download the sample here.


There are a few items to consider when using ArcGIS services via REST in .NET:

  1. You will construct the url that will execute an operation on the server. Inputs to the operation are included in the url as parameters with values. Add a reference to the System.Web.dll and use the HttpUtility class to encode parameter values in the url.
  2. In most cases you will return results in JSON (JavaScript Object Notation) format. Add a reference to the System.Web.Extensions.dll (included with .NET 3.5, separate install for .NET 2.0) and use the JavaScriptSerializer class to deserialize JSON results into a dictionary you can use more effectively.

This example can easily be modified for use in a .NET CLR trigger for SQL Server to geocode address information upon entry into a table -or- in a batch process to geocode addresses in a database -or- show a location in a WinForm or WPF desktop client. The same idea can cross over into other ArcGIS Server services such as querying layers in a map or executing a geoprocessing service. In any case, you'll find the simplicity of the REST API refreshingly simple for those scenarios where you need to plug a little GIS into your app. One parting note, if you use ArcGIS Online services via REST, you'll need to follow the subscription model for the Web Mapping APIs. For example if you geocode more than 1000 addresses, you'll need to purchase a subscription.

7 comments:

Unknown said...

great post, can you do the same with the updateFeatures method of a FeatureServer?

rex hansen said...

Yes, but the web request method will need to be a POST. The edit operations on a feature service are POST only.

D. Heath Clark said...

thx.

what about a queryTask that uses a complex polygon, lets say 50+ points in a json string? The Javascript API requires proxy server, but is it possible server side c#?

D. Heath Clark said...

NOTE to Self: Never POST anything to a blog/forum late Friday afternoon after a big lunch!!

Issue resolved.

Unknown said...

Thanx for posting....

Shree Ganesh stones

yaklibber924 said...

Would you be enthusiastic about exchanging hyperlinks? best online casinos

moshrabbi121 said...

Nice post. I study one thing more difficult on different blogs everyday. It's going to at all times be stimulating to read content material from other writers and practice a little something from their store. I’d desire to use some with the content on my blog whether or not you don’t mind. Natually I’ll offer you a link in your internet blog. Thanks for sharing. best online casino