I like the motto, "if you can't do in on desktop, you won't be able to do it on server." Keeping this idea in mind, I first wrote the tool as a add-in for ArcMap. This allowed me to debug core business logic for the tool without the complications of the server.
The main difference between a 'desktop tool' and Server Object Extension is the ability to deserialize requests and serialize responses over http. Since I was new to C# and Server Object Extensions, I first published a sample SOE called SimpleRESTSOE from the samples folder of the ArcGIS 10 install directory. This tool was simply an echo service (i.e. pass a string in, and get the string back). Requests declare 'text' and 'f' (output format) parameters as part of a url request:
/echo?text=helloWorld&f=json
and they SOE responds:
{"text":"helloWorld"}
I got the sample SOE registered with Windows using the command:
RegAsm SimpleRESTSOE.dll /codebase
I then registered the SOE with ArcCatalog and the Server Manager using the companion file located in the samples folder (RegisterSimpleRESTSOE.dll).
Once I verified the sample SOE was running, I simply started modifing the rest schema to take my custom parameters. To do this, I modified the CreateRestSchema method of the COM class for the tool. I also added some additional variables to support my business logic:
After modifying the CreateRestSchema method the tool was wired to take the following request:
/echo?hydroshed_id=sa7&location={"x"=-54,"y"=-24}&f=json
I wrapped my business logic in a function and called it from the REST operation's handler EchoInput. THe EchoInput method parses the incoming request, calculates the watershed, and serialize the output.
There is a block of 3 lines towards the bottom that comprise the business logic from my ArcMap tool. The first two are helper functions (CreateInMemoryWorkspace / CreateFCFromGeometry), and the third is the actual watershed operation:
Global Hydrosheds Lookup
I built a small client application to test Find Watershed over the web. In the app, the user first supplies the location by clicking on the map. The click location is passes to the server into a query against the lookup map to determine the hydroshed id then :
building a client
Hi BCDCSpatial,
ReplyDeleteI have posted a version for 10.1
http://studioat.maps.arcgis.com/home/item.html?id=7b79eea8286e462bba9b2891b42d223a