Saturday, March 9, 2019

Steps to secure ArcGIS Server REST Endpoints


These are the steps to secure ArcGIS Server REST Endpoints

1.      Go to ArcGIS Manager. Go the services you want to secure and click on the 'Lock' icon to Lock it. This will lock the application.


2.      Download the 'DotNet' proxy folder from ESRI github (https://github.com/esri/resource-proxy/) and install it in the wwwroot folder.

3.      Inside this 'DotNet' folder edit the proxy.config file add an entry like shown here.
<serverUrl url="http://localhost:6080/arcgis/rest/services" matchAll="true" username="<ArcGIS Site Username>" password="<ArcGIS Site Password>"/>

4.      Perform a ping operation like shown here and make sure you are getting results. If not double-check the above steps.
https://<Server Domain Name>/dotnet/proxy.ashx?ping
The reply should be like this.

{ "Proxy Version": "1.1.2", "Configuration File": "OK", "Log File": "Not Exist/Readable"}

5.      Now the site is secure and the proxy is ready for communication.

6.      In your JavaScript API code. Add these lines in the beginning.

        urlUtils.addProxyRule({
            urlPrefix: "https://<Server Domain Name>",
            proxyUrl: "https://<Server Domain Name>/DotNet/proxy.ashx"
        });

7.      Now all your JavaScript REST endpoint calls will go through proxy and your services will remain protected.

Happy Coding !

Visual Studio Code Icon Names


When writing an extension for Visual Studio Code, there might be a need to know the Visual Studio Icon names.

Here is the link which shows all the available icon names.

Hope this helps.

Cheers
Adam

How to call your own Javascript Function from Angular 4 Typescript Application


To call your own JavaScript Function from Angular 4 Typescript Application follow this technique.

In file .angular-cli.json

      "scripts": [
        "../node_modules/adam-scripts/core.js"
      ],

The core.js file contains this function.

function ShowMessage(inMessage) {
    alert(inMessage);
}

In the Typescript file refer and call it like this.

declare var ShowMessage: any;

  ngOnInit() {
    ShowMessage('Working');
  }


XML to C# Objects using JSON - Translate List of Objects


Let’s presume that there is an XML Array like this.

<Books>
<Book>
 <Name>Book Name 1</Name>
 <Author>Author 1</Author>
</Book>
<Book>
 <Name>Book Name 2</Name>
 <Author>Author 2</Author>
</Book>
<Book>
 <Name>Book Name 3</Name>
 <Author>Author 3</Author>
</Book>
</Books>

You can extract the data into C# objects using XML serialization. But XML Serialization will only work if the outer most element is like this.

<ArrayOfBook></ArrayOfBook>

For some reason, if your XML from the SQL server is not like this then you have to use XML attributes in the class definition of “Book” correctly and also create a collection class for the Book List.

The other alternative is to use Newtonsoft JSON. Here is the function to do it.

if (!string.IsNullOrEmpty(inXMLString))
{
    System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
    doc.LoadXml(inXMLString); // Use this line if there is already XML content in a string.
    string jsonText = JsonConvert.SerializeXmlNode(doc);
    dynamic dynObject = JsonConvert.DeserializeObject(jsonText);
    foreach (dynamic innerContents in dynObject.Books)
    {
        List<Book> listOfBooks = new List<Book>();
        string jstring = JsonConvert.SerializeObject(innerContents.Value);
        if (innerContents.Value is JArray)
        {
            listOfBooks = JsonConvert.DeserializeObject<List<Book>>(jstring);
        }
        if (innerContents.Value is JObject)
        {
            Book oneBook = JsonConvert.DeserializeObject<Book>(jstring);
            listOfBooks.Add(oneBook);
        }
       togoBooks.AddRange(listOfBooks);
    }
}

return togoBooks;

Hope this helps. Happy coding.

All Blogs so far ...