AnsweredAssumed Answered

Add IFeatureLayer from FeatureServer

Question asked by MickeyO-Neil on Aug 16, 2016
Latest reply on Oct 19, 2016 by MickeyO-Neil



I'm trying to load a IFeatureLayer from a FeatureServer in a ArcGIS Engine 10.3 Application, but I always get a "System.Runtime.InteropServices.COMException" Error Message. (Line is marked with an Error Comment).


What is the Problem of getting the Layers from the Server?

Thank You very much for your help.


    Public Shared Function GetAGSFeatureLayer(ByVal sURL As String) As IFeatureLayer
        Dim pAGSConnectionFactory As IAGSServerConnectionFactory
        Dim pConnectionProps As IPropertySet
        Dim pAGSConnection As IAGSServerConnection
        Dim enumServerObjectName As IAGSEnumServerObjectName
        Dim pServerObjectName As IAGSServerObjectName3
        Dim pName As IName
        Dim pObject As Object
        Dim pServerSymbolOutputOptions As IServerSymbolOutputOptions
        Dim pGraphicFeatureLayers As IGraphicFeatureLayers
        Dim pGraphicFeatureLayer As IGraphicFeatureLayer2
        Dim pGraphicFeatureServer As IGraphicFeatureServer


            pConnectionProps = New PropertySet
            pConnectionProps.SetProperty("URL", sURL)
            pAGSConnectionFactory = New AGSServerConnectionFactory
            pAGSConnection = pAGSConnectionFactory.Open(pConnectionProps, 0)


            enumServerObjectName = pAGSConnection.ServerObjectNames
            pServerObjectName = enumServerObjectName.Next


            Do Until pServerObjectName Is Nothing


                If pServerObjectName.Type.Equals("FeatureServer", StringComparison.OrdinalIgnoreCase) Then
                    pName = pServerObjectName
                    pObject = pName.Open


                    If TypeOf pObject Is IGraphicFeatureServer Then


                        pServerSymbolOutputOptions = New ServerSymbolOutputOptions
                        pServerSymbolOutputOptions.ConvertLabelExpressions = False
                        pServerSymbolOutputOptions.PictureOutputType = esriServerPictureOutputType.esriServerPictureOutputAsPNG


                        pGraphicFeatureServer = pObject
                        pGraphicFeatureLayers = pGraphicFeatureServer.GetLayers(pServerSymbolOutputOptions) 'ERROR


                        If pGraphicFeatureLayers.Count > 0 Then
                            For i As Integer = 0 To pGraphicFeatureLayers.Count - 1


                                pGraphicFeatureLayer = pGraphicFeatureLayers.Element(i)
                                If TypeOf pGraphicFeatureLayer Is IFeatureLayer Then
                                    Return pGraphicFeatureLayer
                                End If
                        End If
                    End If


                End If
                pServerObjectName = enumServerObjectName.Next
        Catch ex As Exception
            logger.Error("GetAGSFeatureLayer", ex)
        End Try
        Return Nothing
    End Function