I have tried VB sample code on esri site. it is not working.
Please advise!
<Grid x:Name="LayoutRoot"> <!-- Add a Map Control. Zoom to the East-Central United States. --> <esri:Map Background="White" HorizontalAlignment="Left" Margin="0,204,0,0" Name="Map1" VerticalAlignment="Top" Height="350" Width="500" Extent="-10349730,3871622,-8642421,5066738"> <!--Add an ArcGISTiledMapServiceLayer as a backdrop. It has uses SpatialReference WKID=102100 (3857). --> <esri:ArcGISTiledMapServiceLayer ID="myArcGISTiledMapServiceLayer" Url="http://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer" /> </esri:Map> <!-- Button to add a Dynamic Layer (using QueryDataSource) via code-behind. --> <Button Content="Add a QueryDataSource based Dynamic Layer" Height="23" HorizontalAlignment="Left" Margin="0,175,0,0" Name="Button1" VerticalAlignment="Top" Width="500" Click="Button1_Click"/> <!-- Provide the instructions on how to use the sample code. --> <TextBlock Height="145" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="788" TextWrapping="Wrap" Text="Click the button to add a Dynamic Layer (the state of Kentucky) via code-behind using a QueryDataSource. The Dynamic Layers used in this example code are based upon using a LayerDataSource that is undiscoverable via the public ArcGIS Server Directory REST pages. The 'WorkspaceID' and 'DataSourceName' for each Dynamic Layer must be provided to the developer by Manager/Adminstrator of the ArcGISDynamicMapServiceLayer. Examples of the 'WorkspaceID' and 'DataSourceName' are provided as comments in code-behind for a public ArcGIS Server that has Dynamic Layers enabled via the LayerDataSource object."/> </Grid>
Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) ' Add a Layer on-the-fly based on an ArcGISDynamicMapServiceLayer that has Dynamic Layer capabalities enabled. ' The Layer being added DOES NOT come from an existing sub-layer in a LayerMapSource. Rather the Dynamic Layer ' is being generated uses the 'Workspace Type' of 'Database' via the LayerDataSource object. Review the ' ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer Class documentation in the API reference for a full discussion. ' In order to create this Dynamic Layer, information was shared between the Manager/Admininstrator of the ' ArcGISDynamicMapServiceLayer ArcGIS Server service and the application developer. ' ' The Url for the ArcGISDynamicMapServiceLayer is: "http://servicesbeta2.esri.com/arcgis/rest/services/USA/MapServer". ' ' The WorkspaceID used in the LayerDataSource for the Dynamic Layer is: "MyDatabaseWorkspaceIDSSR2" ' ' There are several DataSourceName types associated with the WorkspaceID that could be used to create the Rendering ' of a Dynamic Layer. Think of the DataSourceName as the string name of the layer that will be drawn dynamically. ' A listing of the available DataSourceNames (and their geometry type) are: ' "Demo.DBO.USAreaCodes" <== Polygons ' "Demo.DBO.USCities" <== Points ' "Demo.DBO.USCounties" <== Polygons ' "Demo.DBO.USHighways" <== Polylines ' "Demo.DBO.USLakes" <== Polygons ' "Demo.DBO.USPlaces" <== Points ' "Demo.DBO.USRailroads" <== Polylines ' "Demo.DBO.USRivers" <== Polylines ' "Demo.DBO.USStates" <== Polygons ' Create a QueryDataSource object and set all of it's Properties to valid values. Dim myQueryDataSource As New ESRI.ArcGIS.Client.QueryDataSource myQueryDataSource.GeometryType = ESRI.ArcGIS.Client.Tasks.GeometryType.Polygon Dim myOIDFields As String() = {"OBJECTID"} myQueryDataSource.OIDFields = myOIDFields myQueryDataSource.Query = "SELECT * FROM Demo.DBO.USStates where STATE_NAME = 'Kentucky'" Dim mySpatialReference As New ESRI.ArcGIS.Client.Geometry.SpatialReference(4326) myQueryDataSource.SpatialReference = mySpatialReference myQueryDataSource.WorkspaceID = "MyDatabaseWorkspaceIDSSR2" ' Create a new LayerDataSource and set its DataSource Property to the QueryDataSource. Dim myLayerDataSource As New ESRI.ArcGIS.Client.LayerDataSource myLayerDataSource.DataSource = myQueryDataSource ' Create a new DynamicLayerInfo object and set its ID and Source Properties. Dim myDynamicLayerInfo As New ESRI.ArcGIS.Client.DynamicLayerInfo myDynamicLayerInfo.ID = 102 ' Must be the same as the LayerDrawingOptions.LayerID myDynamicLayerInfo.Source = myLayerDataSource ' Create a new DynamicLayerInfoCollection and add the DynamicLayerInfo object into it. Dim myDynamicLayerInfoCollection As New ESRI.ArcGIS.Client.DynamicLayerInfoCollection myDynamicLayerInfoCollection.Add(myDynamicLayerInfo) ' Create a SimpleFillSymbol (Green Fill, with Black Border, and BorderThickness of 2). Dim mySimpleFillSymbol As New ESRI.ArcGIS.Client.Symbols.SimpleFillSymbol mySimpleFillSymbol.Fill = New System.Windows.Media.SolidColorBrush(Colors.Green) mySimpleFillSymbol.BorderThickness = 2 mySimpleFillSymbol.BorderBrush = New System.Windows.Media.SolidColorBrush(Colors.Black) ' Create a new SimpleRenderer based upon the SimpleFillSymbol. Dim mySimpleRenderer As New ESRI.ArcGIS.Client.SimpleRenderer mySimpleRenderer.Symbol = mySimpleFillSymbol ' Create a new LayerDrawingOptions object which is key to applying our custom Rendering of the Dynamic Layer. ' It is imperative that the LayerDrawingOptions.LayerID = DynamicLayerInfo.ID so that the Dynamic Layer draws ' using the new symbology. Dim myLayerDrawingOptions As New ESRI.ArcGIS.Client.LayerDrawingOptions myLayerDrawingOptions.LayerID = 102 ' Must be the same as the DynammicLayerInfo.ID myLayerDrawingOptions.Renderer = mySimpleRenderer ' Create a new LayerDrawinOptionsCollection and add the LayerDraingOptions object into it. Dim myLayerDrawingOptionsCollection As New ESRI.ArcGIS.Client.LayerDrawingOptionsCollection myLayerDrawingOptionsCollection.Add(myLayerDrawingOptions) ' Create a new Dynamic Layer that is based upon on a LayerDataSource of an ArcGISDynamicMapServiceLayer ' and apply it's custom rendering. Dim myArcGISDynamicMapServiceLayer As New ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer myArcGISDynamicMapServiceLayer.Url = "http://servicesbeta2.esri.com/arcgis/rest/services/USA/MapServer" myArcGISDynamicMapServiceLayer.DisableClientCaching = True myArcGISDynamicMapServiceLayer.DynamicLayerInfos = myDynamicLayerInfoCollection myArcGISDynamicMapServiceLayer.LayerDrawingOptions = myLayerDrawingOptionsCollection ' Add the Dynamic Layer to the Map Control. This causes the round trip server request to occur. Map1.Layers.Add(myArcGISDynamicMapServiceLayer) End Sub