3

I have got an existing .NET C# desktop application which already reads various GIS formats. I would now like to add support to read data from ArcGIS Online.

What options have I got to access information such as services, groups, search data etc from ArcGIS Online? Can I use ArcObjects, REST endpoints?

1
  • Hi Alexander this sample helped me a lot to get information from AGOL using c#. Now I am trying extend your code to add and update feature service use ArcGIS REST API (AddFeatures and UpdateFeatures). Could you help me on how to built the json string ("data"?) for the post? Thanks in advance! The requirement is like tis: resources.arcgis.com/en/help/arcgis-rest-api/index.html#/… Ming
    – user90337
    Commented Jan 25, 2017 at 19:47

2 Answers 2

5

ArcGIS Online has a full REST API: http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#//02r300000267000000

It's also worth mentioning, that the ArcGIS Runtime SDK for WPF and upcoming successor ArcGIS Runtime SDK for .NET provide .NET APIs for interacting with ArcGIS Online items (among many other things).

3
  • Thanks for your reply. Do you know if ArcObjects have classes to interact with ArcGIS Online?
    – James
    Commented Jul 8, 2014 at 8:52
  • Apologies for the late reply. There are ArcObjects classes to consume layer packages and web maps. See e.g. resources.arcgis.com/en/help/arcobjects-net/conceptualhelp/0001/…
    – Philip
    Commented Jul 22, 2014 at 19:08
  • Note for web apps you are not allowed to use the ArcGis Runtime SDK in services only in desktop apps.
    – Jeff
    Commented Feb 7, 2020 at 23:34
3

When using newtonsoft.json assembly, you can make a request to ArcGIS Online passing credentials. Below is my sample C# class that accesses this information from ArcGIS Online. More in-depth knowledge of the REST API as mentioned above would be helpful for any .NET developer.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Collections.Specialized;
using System.Runtime.Serialization;
using Newtonsoft.Json;


namespace reportGenerator
{
class AGOL
{
    private string _token;
    private string _username;
    private string _password;
    public organizationInformation orgInfo;


    public string Token
    {
        get
        {
            return _token;
        }
    }

    public string Username
    {
        get
        {
            return _username;
        }
        set
        {
            _username = value;
        }
    }

    public string Password
    {
        get
        {
            return _password;
        }
        set
        {
            _password = value;
        }
    }
    public AGOL(string UserName, string PassWord)
    {
        _username = UserName;
        _password = PassWord;
        _token = GetToken(UserName, PassWord);
        orgInfo = _getOrgInfo(_token);
    }



    public string GetToken(string username, string password)
    {

        var data = new NameValueCollection();
        data["username"] = Username;
        data["password"] = Password;
        data["referer"] = "https://www.arcgis.com";
        data["f"] = "json";

        TokenInfo x = JsonConvert.DeserializeObject<TokenInfo>(_getResponse(data, "https://arcgis.com/sharing/rest/generateToken"));
        return x.token; ;
    }

    private organizationInformation _getOrgInfo(string token)
    {
        var data = new NameValueCollection();
        data["token"] = token;
        data["f"] = "json";

        organizationInformation x = JsonConvert.DeserializeObject<organizationInformation>(_getResponse(data, "http://www.arcgis.com/sharing/rest/portals/self"));
        return x;
    }

    private string _getResponse(NameValueCollection data, string url)
    {
        string responseData;
        var webClient = new WebClient();
        var response = webClient.UploadValues(url, data);
        responseData = System.Text.Encoding.UTF8.GetString(response);
        return responseData;
    }

    //Starts the collection of useless classes....
    //
    //
    //
    //
    //
    //
    //
    //
    //
    //
    public class TokenInfo
    {
        public string token { get; set; }
        public long expires { get; set; }
        public bool ssl { get; set; }
    }

    public class organizationInformation
    {
        public string access { get; set; }
        public bool allSSL { get; set; }
        public double availableCredits { get; set; }
        public string backgroundImage { get; set; }
        public string basemapGalleryGroupQuery { get; set; }
        public string bingKey { get; set; }
        public bool canListApps { get; set; }
        public bool canListData { get; set; }
        public bool canListPreProvisionedItems { get; set; }
        public bool canProvisionDirectPurchase { get; set; }
        public bool canSearchPublic { get; set; }
        public bool canShareBingPublic { get; set; }
        public bool canSharePublic { get; set; }
        public bool canSignInArcGIS { get; set; }
        public bool canSignInIDP { get; set; }
        public string colorSetsGroupQuery { get; set; }
        public bool commentsEnabled { get; set; }
        public long created { get; set; }
        public string culture { get; set; }
        public string customBaseUrl { get; set; }
        public int databaseQuota { get; set; }
        public int databaseUsage { get; set; }
        public string description { get; set; }
        public string featuredGroupsId { get; set; }
        public string featuredItemsGroupQuery { get; set; }
        public string galleryTemplatesGroupQuery { get; set; }
        public string helpBase { get; set; }
        public string homePageFeaturedContent { get; set; }
        public int homePageFeaturedContentCount { get; set; }
        public int httpPort { get; set; }
        public int httpsPort { get; set; }
        public string id { get; set; }
        public string ipCntryCode { get; set; }
        public bool isPortal { get; set; }
        public string layerTemplatesGroupQuery { get; set; }
        public int maxTokenExpirationMinutes { get; set; }
        public long modified { get; set; }
        public string name { get; set; }
        public string portalHostname { get; set; }
        public string portalMode { get; set; }
        public string portalName { get; set; }
        public object portalThumbnail { get; set; }
        public string region { get; set; }
        public bool showHomePageDescription { get; set; }
        public string staticImagesUrl { get; set; }
        public long storageQuota { get; set; }
        public long storageUsage { get; set; }
        public bool supportsHostedServices { get; set; }
        public bool supportsOAuth { get; set; }
        public string symbolSetsGroupQuery { get; set; }
        public string templatesGroupQuery { get; set; }
        public string thumbnail { get; set; }
        public string units { get; set; }
        public string urlKey { get; set; }
        public bool useStandardizedQuery { get; set; }
    }
}
}

I hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.