Hello,
I am using AGM 10.2 and I am trying to download data from an AGOL feature service.
I am using the rest API to generate the token by passing the credentials. When I append the token to the service url in a browser, it works fine.
However when using the feature sync agent in AGM 10.2, it comes up with
{System.UriFormatException: Invalid URI: The format of the URI could not be determined.
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri..ctor(String uriString)
at System.Web.Services.Protocols.WebClientProtocol.set_Url(String value)
at ESRI.ArcGIS.Mobile.FeatureCaching.Synchronization.BinaryWebService..ctor(String url)
at ESRI.ArcGIS.Mobile.FeatureCaching.Synchronization.MobileServiceConnection.get_WebClientProtocol()
at ESRI.ArcGIS.Mobile.FeatureCaching.Synchronization.MobileServiceConnection.get_IsValid()
at ESRI.ArcGIS.Mobile.FeatureCaching.Synchronization.FeatureSyncAgent.Synchronize()}
I have tried to encode the url, but it doesn't make any difference. See below code. Has anyone successfully
synchronised with AGOL feature service using token. Any other suggestions?
string token = GetToken(); //Uses REST API
MobileServiceConnection msc = new MobileServiceConnection();
msc.Url = MobileApplication.Current.Project.FindFeatureSourceInfo(currentLayer).CacheMapLayerInfo.Url;
msc.TokenCredential = new ESRI.ArcGIS.Mobile.CatalogServices.TokenCredential("username1", "password1");
msc.Url += "?token=" + token;
msc.Url = HttpUtility.UrlEncode(msc.Url);
syncAgent = new FeatureSyncAgent(currentLayer, msc);
syncAgent.SynchronizationDirection = SyncDirection.DownloadOnly;
syncAgent.DownloadFilter = pQFilter;
if (!syncAgent.IsValid)
{
MessageBox.ShowDialog(GetMessage("msg_101"), stackFrame.GetMethod().Name, System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
return isDownloadSuccessful;
}
syncAgent.ProgressChanged += new EventHandler<FeatureSyncProgressEventArgs>(syncAgent_ProgressChanged);
//syncAgent.ProgressChanged += new EventHandler<FeatureLayerSyncProgressEventArgs>(syncAgent_ProgressChanged);
syncAgent.StateChanged += new EventHandler(syncAgent_StateChanged);
//syncResults = syncAgent.Synchronize() as FeatureLayerSyncResults;
try
{
syncResults = syncAgent.Synchronize() as FeatureSyncResults;
syncAgent.ProgressChanged -= syncAgent_ProgressChanged;
syncAgent.StateChanged -= syncAgent_StateChanged;
}
catch (System.Exception ex)
{
ErrorHandlerWithDetails.Show(ex, GetMessage("msg_101"));
}