Developing with feature services

The ability to include feature services in mobile applications means that the same feature services used in web applications can be consumed in mobile applications. Similar to mobile services that allow data to be stored locally on a device for disconnected uses including editing, feature services can be consumed by a mobile application. The feature service is treated as a feature source, the same way as other operational layers. The feature service is used to download data to a device, which stores the data in a local mobile cache. The mobile application can then use this mobile cache in a disconnected environment to display, query, and update the data. These capabilities have been written to minimize the impact on current applications by using the existing mobile cache for storage, implementing this functionality as a feature source that follows the existing behavior, and acts like the other map layers.

See Publishing a hosted feature service for details on how to correctly establish the feature service in your mobile applications.

The feature service functionality has been implemented using two classes: FeatureServiceReplicaManager and FeatureServiceReplicaResults. The creation of these two classes means that the methods used to interact with a feature service have been centralized within these classes, and other classes that consume this data do not require additional customization.

The FeatureServiceReplicaManager class has some key required properties that must be set including the following:

The FeatureServiceReplicaManager class also contains multiple methods for accessing the feature service, and they all include synchronous and asynchronous versions. Initialize is used to establish connection with the feature service and returns a Boolean value. CreateReplica is used to get data from the feature service to the local cache, and it can optionally use an envelope to limit the size of the data transfer. Register\UnRegister is used to register and unregister a mobile cache with a feature service, which is necessary after the service is disconnected from the local cache before synchronizing to ensure edits are not lost. Synchronize is used to update both the server and client with any changes made between service and client. DownloadAttachment is used to download attachments from the service, and returns a Boolean to indicate success.

//FeatureService Connection using replicamanager
      string featServiceUrl = @"http://services.arcgis.com/<hostedservice>/arcgis/rest/services/<myservice/FeatureServer";
      FeatureServiceReplicaManager  fsreplica = new FeatureServiceReplicaManager();
      //MobileCache 
      string cacheStoragePath = @"C:\COGS\data\FSCache";
      MobileCache mobileCache = new MobileCache(cacheStoragePath);
      //delete old cache
      if (mobileCache.CacheExists == true) 
        mobileCache.DeleteCache();
						////////////////////////////
      //Create a token to access the service with valid username\password
      TokenCredential token = new TokenCredential("Username", "PassWord");
						//Set feature service properties
      fsreplica.TokenCredential = token;
      fsreplica.Url = featServiceUrl;
      fsreplica.Initialize();
      fsreplica.MobileCache = mobileCache;
  
      //Get the data from the service to the local cache 
      fsreplica.CreateReplica();  
      //Open the cache and add it to the maplayers 
      mobileCache.Open();
      if (!fsreplica.IsRegistered )
        fsreplica.RegisterReplica();  
      map1.MapLayers.Add(mobileCache);
1/7/2015