Skip to content

Migrate to RESTful Automation API

Chao Wang edited this page Aug 17, 2020 · 3 revisions

Important

ArcGIS Earth V1.11 has been migrated to .Net Core 3.1, and the Automation API has also undergone major changes. The previous version of Automation API for ArcGIS Earth V1.10 was based on .NET WCF NamedPipe, and v1.11 started to be implemented in a RESTful way.

Code Sample

Now, please forget the complicated and cumbersome code of NamedPipe. In the new RESTful code, you only need the following simple commands to achieve the previously desired functions

Get Camera

private async Task<string> GetCamera()
{
    //  API url
    string cameraRequestUrl = "http://localhost:8000/arcgisearth/Camera";
    //  Send request and get response 
    var httpClient = new HttpClient();
    HttpResponseMessage responseMessage = await httpClient.GetAsync(cameraRequestUrl);
    //  Get string content form the response
    HttpContent content = responseMessage.Content;
    return await content.ReadAsStringAsync();       
}

Set Camera

private async Task<string> SetCamera(string inputJsonStr)
{
    //  API url
    string cameraRequestUrl = "http://localhost:8000/arcgisearth/Camera";    
    //  Convert string request content to HttpContent
    byte[] data = Encoding.UTF8.GetBytes(json);
    var byteArrayContent = new ByteArrayContent(data);
    byteArrayContent.Headers.Add("Content-Type", "application/json");        
    //  Send request and get response 
    var httpClient = new HttpClient();
    HttpResponseMessage responseMessage = await httpClient.PutAsync(cameraRequestUrl, byteArrayContent);        
    //  Get string content form the response
    HttpContent content = responseMessage.Content;
    return await content.ReadAsStringAsync();
}

Add Layer

private async Task<string> AddLayer(string inputJsonStr)
{  
    //  API url
    string layerRequestUrl = "http://localhost:8000/arcgisearth/Layer";        
     //  Convert string request content to HttpContent
    byte[] data = Encoding.UTF8.GetBytes(json);
    var byteArrayContent = new ByteArrayContent(data);
    byteArrayContent.Headers.Add("Content-Type", "application/json");  
    //  Send request and get response 
    var httpClient = new HttpClient();
    HttpResponseMessage responseMessage = await httpClient.PostAsync(layerRequestUrl, byteArrayContent);
    return await GetResponseContent(responseMessage);
}

And so on.

Help

For REST API request and response specifications, please refer to the API help page http://localhost:8000/swagger/index.html

For more use cases, you can refer to the AutomationAPIHelper class in the ArcGISEarth.AutoAPI.Utils project This class encapsulates all the methods used.

Clone this wiki locally