Click or drag to resize

Credential Class

Base class that represents a credential object used to access a secured ArcGIS resource.
Inheritance Hierarchy

Namespace:  Esri.ArcGISRuntime.Security
Assembly:  Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version:
public abstract class Credential : INotifyPropertyChanged, 

The Credential type exposes the following members.

Public propertyCode exampleServiceUri
Gets or sets the URI of the service that can be accessed with this credential.
Public eventPropertyChanged
Occurs when a property value changes.
You will generally get an instance of this class by calling GetCredentialAsync.


Example Name: FindRoute

Display directions for a route between two points.

Code example screen shot.

// Copyright 2017 Esri.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
// language governing permissions and limitations under the License.

using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;
using Esri.ArcGISRuntime.Tasks.NetworkAnalysis;
using Esri.ArcGISRuntime.UI;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows;

namespace ArcGISRuntime.WPF.Samples.FindRoute
        "Find a route",
        "Network Analysis",
        "This sample demonstrates how to solve for the best route between two locations on the map and display driving directions between them.",
    public partial class FindRoute
        // List of stops on the route ('from' and 'to')
        private List<Stop> _routeStops;

        // Graphics overlay to display stops and the route result
        private GraphicsOverlay _routeGraphicsOverlay;

        // URI for the San Diego route service
        private Uri _sanDiegoRouteServiceUri = new Uri("");

        // URIs for picture marker images
        private Uri _checkedFlagIconUri = new Uri("");

        private Uri _carIconUri = new Uri("");

        public FindRoute()

            // Create the map, graphics overlay, and the 'from' and 'to' locations for the route

        private void Initialize()
            // Define the route stop locations (points)
            MapPoint fromPoint = new MapPoint(-117.15494348793044, 32.706506537686927, SpatialReferences.Wgs84);
            MapPoint toPoint = new MapPoint(-117.14905088669816, 32.735308180609138, SpatialReferences.Wgs84);

            // Create Stop objects with the points and add them to a list of stops
            Stop stop1 = new Stop(fromPoint);
            Stop stop2 = new Stop(toPoint);
            _routeStops = new List<Stop> {stop1, stop2};

            // Picture marker symbols: from = car, to = checkered flag
            PictureMarkerSymbol carSymbol = new PictureMarkerSymbol(_carIconUri);
            PictureMarkerSymbol flagSymbol = new PictureMarkerSymbol(_checkedFlagIconUri);

            // Add a slight offset (pixels) to the picture symbols.
            carSymbol.OffsetX = -carSymbol.Width / 2;
            carSymbol.OffsetY = -carSymbol.Height / 2;
            flagSymbol.OffsetX = -flagSymbol.Width / 2;
            flagSymbol.OffsetY = -flagSymbol.Height / 2;

            // Create graphics for the stops
            Graphic fromGraphic = new Graphic(fromPoint, carSymbol);
            Graphic toGraphic = new Graphic(toPoint, flagSymbol);

            // Create the graphics overlay and add the stop graphics
            _routeGraphicsOverlay = new GraphicsOverlay();

            // Get an Envelope that covers the area of the stops (and a little more)
            Envelope routeStopsExtent = new Envelope(fromPoint, toPoint);
            EnvelopeBuilder envBuilder = new EnvelopeBuilder(routeStopsExtent);

            // Create a new viewpoint apply it to the map view when the spatial reference changes
            Viewpoint sanDiegoViewpoint = new Viewpoint(envBuilder.ToGeometry());
            MyMapView.SpatialReferenceChanged += (s, e) => MyMapView.SetViewpoint(sanDiegoViewpoint);

            // Add a new Map and the graphics overlay to the map view
            MyMapView.Map = new Map(Basemap.CreateStreetsVector());

        private async void SolveRouteClick(object sender, System.Windows.RoutedEventArgs e)
                // Create a new route task using the San Diego route service URI
                RouteTask solveRouteTask = await RouteTask.CreateAsync(_sanDiegoRouteServiceUri);

                // Get the default parameters from the route task (defined with the service)
                RouteParameters routeParams = await solveRouteTask.CreateDefaultParametersAsync();

                // Make some changes to the default parameters
                routeParams.ReturnStops = true;
                routeParams.ReturnDirections = true;

                // Set the list of route stops that were defined at startup

                // Solve for the best route between the stops and store the result
                RouteResult solveRouteResult = await solveRouteTask.SolveRouteAsync(routeParams);

                // Get the first (should be only) route from the result
                Route firstRoute = solveRouteResult.Routes.First();

                // Get the route geometry (polyline)
                Polyline routePolyline = firstRoute.RouteGeometry;

                // Create a thick purple line symbol for the route
                SimpleLineSymbol routeSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Purple, 8.0);

                // Create a new graphic for the route geometry and add it to the graphics overlay
                Graphic routeGraphic = new Graphic(routePolyline, routeSymbol);

                // Get a list of directions for the route and display it in the list box
                IReadOnlyList<DirectionManeuver> directionsList = firstRoute.DirectionManeuvers;
                DirectionsListBox.ItemsSource = directionsList;
            catch (Exception ex)
                MessageBox.Show(ex.ToString(), "Error");

        private void ResetClick(object sender, System.Windows.RoutedEventArgs e)
            // Clear the list of directions
            DirectionsListBox.ItemsSource = null;

            // Remove the route graphic from the graphics overlay (only line graphic in the collection)
            int graphicsCount = _routeGraphicsOverlay.Graphics.Count;
            for (int i = graphicsCount; i > 0; i--)
                // Get this graphic and see if it has line geometry
                Graphic g = _routeGraphicsOverlay.Graphics[i - 1];
                if (g.Geometry.GeometryType == GeometryType.Polyline)
                    // Remove the graphic from the overlay
<UserControl x:Class="ArcGISRuntime.WPF.Samples.FindRoute.FindRoute"
        <esri:MapView x:Name="MyMapView" />
        <Border Style="{StaticResource BorderStyle}">
                <TextBlock Text="Route directions:"
                           FontWeight="SemiBold" />
                <ListBox x:Name="DirectionsListBox"
                        <DataTemplate DataType="networkAnalysis:DirectionManeuver">
                            <TextBlock Text="{Binding DirectionText}" TextWrapping="Wrap" />
                <Button x:Name="SolveRouteButton"
                        Content="Solve Route"
                        Click="SolveRouteClick" />
                <Button x:Name="ResetButton"
                        Click="ResetClick" />
See Also
Additional Examples
Hyperlink to ExampleDescription
AuthorMapCreate and save a map as an ArcGIS `PortalItem` (i.e. web map).
CertificateAuthenticationWithPkiAccess secured portals using a certificate.
ClosestFacilityFind a route to the closest facility from a location.
ClosestFacilityStaticFind routes from several locations to the respective closest facility.
EditAndSyncFeaturesSynchronize offline edits with a feature service.
ExportTilesDownload tiles to a local tile cache file stored on the device.
FindAddressFind the location for an address.
FindPlaceFind places of interest near a location or within a specific area.
FindRouteDisplay directions for a route between two points.
FindServiceAreaFind the service area within a network from a given point.
FindServiceAreasForMultipleFacilitiesFind the service areas of several facilities from a feature service.
GenerateGeodatabaseGenerate a local geodatabase from an online feature service.
GenerateOfflineMapTake a web map offline.
GenerateOfflineMapWithOverridesUse the `OfflineMapTask` with overrides to take a webmap offline. The overrides workflow allows you to adjust the settings used for taking each layer in the map offline. For a simple example of how you take a map offline, please consult the "Generate Offline Map" sample.
GeodatabaseTransactionsThis sample demonstrates how to manage edits to a local geodatabase inside of transactions.
IntegratedWindowsAuthUse Windows credentials to access services hosted on a portal secured with Integrated Windows Authentication (IWA).
ListRelatedFeaturesList features related to the selected feature.
OAuthThis sample demonstrates how to authenticate with ArcGIS Online (or your own portal) using OAuth2 to access secured resources (such as private web maps or layers). Accessing secured items requires a login on the portal that hosts them (an ArcGIS Online account, for example).
OfflineBasemapByReferenceUse the `OfflineMapTask` to take a web map offline, but instead of downloading an online basemap, use one which is already on the device.
OfflineGeocodeGeocode addresses to locations and reverse geocode locations to addresses offline.
ReverseGeocodeUse an online service to find the address for a tapped point.
RouteAroundBarriersFind a route that reaches all stops without crossing any barriers.
SearchPortalMapsFind webmap portal items by using a search term.
TokenSecuredChallengeThis sample demonstrates how to prompt the user for a username and password to authenticate with ArcGIS Server to access an ArcGIS token-secured service. Accessing secured services requires a login that's been defined on the server.