Use ArcGIS Server REST resources without an official SDK more information.
It can also be used for just working with types and as well as some ArcGIS Server types you can also use GeoJSON FeatureCollections with the ability to convert GeoJSON <-> ArcGIS Features.
Typical use case would be the need to call some ArcGIS REST resource from server .NET code or maybe a console app. Rather than having to fudge a dependency to an existing SDK you can use this. Works with .NET for Windows Store apps, .NET framework 4 and higher, Windows Phone 8 and higher and Xamarin iOS and Android.
Since the serialization is specific to your implementation you will need to create an ISerializer to use in your gateway. There are NuGet packages created for 2 of these called ArcGIS.PCL.JsonDotNetSerializer
and ArcGIS.PCL.ServiceStackV3Serializer
. To use one of these add a reference using NuGet then call the static Init()
method e.g. ArcGIS.ServiceModel.Serializers.JsonDotNetSerializer.Init()
. This will create an ISerializer
instance and override the SerializerFactory.Get()
method so that it is returned when requested. This also means that you no longer have to pass the ISerializer
to your gateway or token providers when initialising them, though you can still use this mechanism if you prefer.
Supports the following as typed operations:
CheckGenerateToken
- create a token automatically via anITokenProvider
Query<T>
- query a layer by attribute and / or spatial filtersQueryForCount
- only return the number of results for the query operationQueryForIds
- only return the ObjectIds for the results of the query operationFind
- search across n layers and fields in a serviceApplyEdits<T>
- post adds, updates and deletes to a feature service layerGeocode
- single line of input to perform a geocode using a custom locator or the Esri world locatorSuggest
- lightweight geocode operation that only returns text results, commonly used for predictive searchingReverseGeocode
- find location candidates for a input point locationSimplify<T>
- alter geometries to be topologically consistentProject<T>
- convert geometries to a different spatial referenceBuffer<T>
- buffers geometries by the distance requestedDescribeSite
- returns a url for every service discoveredPing
- verify that the server can be accessedPublicKey
- admin operation to get public key used for encryption of token requestsServiceStatus
- admin operation to get the configured and actual status of a service
Some examples of it in use for server side processing in web sites
- [Describe site] (https://arcgissitedescriptor.azurewebsites.net/) - code
- [Convert between GeoJSON and ArcGIS Features] (http://arcgisgeojson.azurewebsites.net/) - code
- [Server side geometry operations] (http://eqnz.azurewebsites.net/) - code
- [Server side geocode] (http://loc8.azurewebsites.net/map?text=wellington, new zealand) - code
See some of the tests for some example calls.
###Gateway Use Cases
// ArcGIS Server with non secure resources
var gateway = new PortalGateway("http://sampleserver3.arcgisonline.com/ArcGIS/");
// ArcGIS Server with secure resources
var secureGateway = new SecureArcGISServerGateway("http://serverapps10.esri.com/arcgis", "user1", "pass.word1");
// ArcGIS Server with secure resources and token service at different location
var otherSecureGateway = new PortalGateway("http://sampleserver3.arcgisonline.com/ArcGIS/", tokenProvider: new TokenProvider("http://serverapps10.esri.com/arcgis", "user1", "pass.word1"));
// ArcGIS Online either secure or non secure
var arcgisOnlineGateway = new ArcGISOnlineGateway();
var secureArcGISOnlineGateway = new ArcGISOnlineGateway(tokenProvider: new ArcGISOnlineTokenProvider("user", "pass"));
var secureArcGISOnlineGatewayOAuth = new ArcGISOnlineGateway(tokenProvider: new ArcGISOnlineAppLoginOAuthProvider("clientId", "clientSecret"));
Once you have a gateway you can call operations on it, for example to query an endpoint
var queryPoint = new Query("Earthquakes/EarthquakesFromLastSevenDays/MapServer/0".AsEndpoint());
var resultPoint = await gateway.Query<Point>(queryPoint);
You may have noticed the AsEndpoint()
method in the Query
constructor above. This is an extension method that creates a new ArcGISServerEndpoint
and you can use the constructor for that if you prefer.
The available endpoint types are
ArcGISServerEndpoint
- this will create an endpoint at therest/services
location for an ArcGIS server gateway. This is the most common use case for your own services so it's likely you will use this oneArcGISOnlineEndpoint
- this will create an endpoint at thesharing/rest
location. This can be used when called services hosted on ArcGIS Online or Portal for ArcGISArcGISServerAdminEndpoint
- this will create an endpoint at theadmin
location for an ArcGIS server gatewayAbsoluteEndpoint
- this will just keep the string that you pass to it. It's used internally to allow theArcGISOnlineEndpoint
to call the geometry service at https://utility.arcgisonline.com/arcgis/rest/services/Geometry/GeometryServer
There are a couple of platform specific classes used by the PortalGateway
that can be overridden if you want to (I use a poor mans DI). The first is the HttpClient
. This gets resolved by calling the Get
function of the HttpClientFactory
. So you can alter this by setting that function to return whatever you want instead.
HttpClientFactory.Get = (() => new SomeHttpClient());
The other place you can do something similar if the CryptoProviderFactory
. This is used for automatically encrypting token requests but you may want to change the behaviour or more likely only use encryption for some of the token requests. The easiest way to do this is to disable the automatic encryption and then pass the ICryptoProvider
to your TokenProvider
when needed.
// Disable auto encryption
CryptoProviderFactory.Disabled = true;
// No encryption for this token provider
var tokenProvider = new TokenProvider("serverUrl", "username", "password");
// This one will still have encryption
var tokenProviderEncrypted = new TokenProvider("serverUrl", "username", "password", cryptoProvider: new RsaEncrypter());
If you have NuGet installed, the easiest way to get started is to install via NuGet:
PM> Install-Package ArcGIS.PCL
On Xamarin you can add the ArcGIS.PCL component from the component store or use NuGet since it is now supported in Xamarin Studio.
Of course you can also get the code from this site.
Icon made by Freepik from www.flaticon.com