I am trying to create a layer and add it into a MapControl from ArcGIS REST URL. For example I use the following URL http://sampleserver6.arcgisonline.com/arcgis/rest/services/EmergencyFacilities/MapServer

I can do this with the help of this post

However, the code in the post seems to derive a SOAP url from the REST url. So I have few questions regarding this.

  1. Can I create the layer without deriving a SOAP url from the REST url.
  2. Does it always guaranteed that the SOAP url can be derived in this way. For example If the service URL uses the "URL mapping", how will this method work? For instance how can I work with this URL https://maps.stats.govt.nz/wss/service/arcgis1/guest
  • Would you be able to edit your question to focus it on whichever of your two questions is more important to you, please? As per the Tour, you can always research/ask the other one separately.
    – PolyGeo
    Aug 4, 2014 at 21:23
  • Well I think that solution for first question may work for the second one as well. So first question is more important.
    – sidd
    Aug 4, 2014 at 22:47

2 Answers 2


In Arc 10.2 you can use IMapServerRESTLayer. Using this avoids using SOAP. Here is some code (VB.Net) that shows how it is used, with some extra code. This code is for a AddIn button. The extra code checks if the connection is OK by requesting a json file. Also, there is code for displaying the json file, and getting the REST file general information. I have not figured out a way of getting the other layer properties such as those under the source tab i.e. Data Type.

The url is typical. You need to find the url by going to the web service and looking it up.

There are other ways of NOT using SOAP. This article by Anthony Baker talks about using json files to consume REST services. Also the background information in http://rest.elkstein.org/2008/02/what-is-rest.html is very good.

Here is the code (tested under Arc10.2) Protected Overrides Sub OnClick() Const csProceedureName As String = "cmdListBaseMap_OnClick" MsgBox("In text version")

        Dim pApp As IApplication
        Dim pMxDoc As IMxDocument
        Dim pMap As IMap
        Dim pView As IActiveView
        Dim resturl As String

        resturl = "http://services.thelist.tas.gov.au/arcgis/rest/services/Basemaps/Topographic/ImageServer/?f=lyr"        ' v2 ' works

        ' there was a problem getting the interface to work. 
        ' In addition to carto needed to include ESRI.ArcGIS.DataSourceRaster
        Dim RESTLayer As IMapServerRESTLayer
        RESTLayer = New MapServerRESTLayer

        Dim pLayer As ILayer

        pApp = My.ArcMap.Application
        pMxDoc = pApp.Document
        pMap = pMxDoc.FocusMap
        pView = pMxDoc.ActiveView

        ' this is done to test the connection
        ' Use web HttpWebRequest to see if connection OK and so can retrieve file
        Dim request_json_url As String = "http://services.thelist.tas.gov.au/arcgis/rest/services/Basemaps/Topographic/ImageServer/?f=json"
        Dim request As HttpWebRequest = DirectCast(HttpWebRequest.Create(request_json_url), HttpWebRequest)
        Dim response As HttpWebResponse = DirectCast(request.GetResponse, HttpWebResponse)

        If response.StatusCode = HttpStatusCode.OK Then
            ' connection and response OK
            'MsgBox("Status Code " & response.StatusCode & vbNewLine & " Status description " & response.StatusDescription & vbNewLine & " Encoding " & response.CharacterSet)

            '' this is one method of getting the json file
            ''Dim encoding As Text.Encoding = System.Text.Encoding.GetEncoding(response.CharacterSet)
            ''Dim reader As New StreamReader(response.GetResponseStream(), encoding)
            ''Dim streamtext As String = reader.ReadToEnd()

            ' '' use a webclient to check connection, the try cast does exception handling
            ''Dim wc As WebClient = New WebClient
            ''Dim response_client As String
            ''    response_client = wc.DownloadString(request_json_url)
            ''    MsgBox(response_client)

            ' Get the Rest layer

            ' Cast to ILayer so it can be added to map
            ' this cast works
            pLayer = TryCast(RESTLayer, ILayer)
            If pLayer Is Nothing Then
                MsgBox("ERROR ( " & csProceedureName & ")  Cast from MapServerRESTLayer to Ilayer failed")
                'MsgBox("Cast from MapServerRESTLayer to Ilayer OK")
            End If

            ' add layer to map

            '' This works
            '' Returns the Description 
            '' Dim pGenProperties As ILayerGeneralProperties
            ''pGenProperties = TryCast(pLayer, ILayerGeneralProperties)
            ''If pGenProperties Is Nothing Then
            ''    MsgBox("No general properties")
            ''    MsgBox("Properties -" & pGenProperties.LayerDescription & "-")
            ''End If

            MsgBox("ERROR ( " & csProceedureName & " ) " & response.StatusCode & vbNewLine & response.StatusDescription)
        End If

    Catch ex As Exception
        MsgBox("Error " & ex.Message)
    End Try


In 10.2 you would probably be able to use IMapServerRESTLayer. I haven't tried it myself as I'm stuck with 10.0.

In 10.0 we wrote our own layer type using the plug-in datasource framework: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Plug_in_data_sources/000100000003000000/ It's a lot of work and you probably only want to implement what you really need. The layer will be read only. The basic principle is that you implement a couple of interfaces that create rest requests and parses the result to create arcobjects objects.

  • WARNING. There is a bug in this code. A json request is made to this url. If the returned response.status_code is Ok then a RESTLayer is created directly using RESTLayer.Connect(url) this is then cast as an ILayer. The RESTLayer is a IMapServerRESTLayer, but the ILayer assumes a MapServer layer, so making a implicit cast. ArcMap thus shows the layer as a MapServer layer rather than a ImageServer layer. This mixup will cause a ArcMap crash if there is no imageservice Nov 22, 2019 at 1:37

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.