Select to view content in your preferred language

Using Secure Services with Query task, editor widget, etc..

1017
7
10-03-2011 07:39 AM
MattMiley
Deactivated User
I need to use secure services with Query tasks, editor widget, etc.. All I was able to accomplish so far was authenticating using this blog post http://blogs.esri.com/Dev/blogs/silverlightwpf/archive/2010/02/15/How-to-use-secure-ArcGIS-Server-se...
Can someone point me to some source code or point me in the right direction.

I have the token as a string in my Code. Is there a way i can just bind the token to the layer's token attribute in the xaml?

Thanks
0 Kudos
7 Replies
MattMiley
Deactivated User
Well i figured out how to query with the token

QueryTask queryTask =
                   new QueryTask("http://myGISserver/ArcGIS/rest/services/secure/Water_Utilites_Job_Log/MapServer/0");
                queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted;
                queryTask.Failed += QueryTask_Failed;
                queryTask.Token = theToken;


Can anyone make my day and teach me how to get the editor widget to work now?
0 Kudos
JenniferNery
Esri Regular Contributor
ProxyUrl and Token when set on FeatureLayer will also be used by Editor, TemplatePicker and EditorWidget. This bug fix has been included in our v2.3 and v3.0. You can try the v3.0 beta 1 if you have signed up for 10.1 Beta program: http://beta.esri.com/community/
You can look at the "Editing" samples in our SDK: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#ToolkitEditorWidget
0 Kudos
MattMiley
Deactivated User
http://beta.esri.com/community/[/URL]


The editor widget loads and lets me add new features, except the I can't add any attributes. Or modify existing attributes. Is this happening because it is still in beta? I added my code for reference.

  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:esri="http://schemas.esri.com/arcgis/client/2009">

    <Grid x:Name="LayoutRoot" Background="White">

        <esri:Map Name="MyMap" WrapAround="True" Extent="-15000000,2000000,-7000000,8000000">
            <esri:ArcGISTiledMapServiceLayer ID="Street Map" 
                    Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
        </esri:Map>

        <esri:MapProgressBar x:Name="MyProgressBar" 
   Map="{Binding ElementName=MyMap}"
   HorizontalAlignment="Center" VerticalAlignment="Center"
   Width="200" Height="36"
   Margin="25"  />

        <Grid Name="LoginGrid" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,15,15,0">


            <Rectangle Stroke="Gray" RadiusX="10" RadiusY="10" Fill="LightGray" Margin="-10" >
                <Rectangle.Effect>
                    <DropShadowEffect/>
                </Rectangle.Effect>
            </Rectangle>

            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>

                <TextBlock Text="Username" Grid.Column="0" Grid.Row="0"
                        Margin="2" VerticalAlignment="Center" />
                <TextBox Name="UserTextBox" Text="    " HorizontalAlignment="Right" Margin="2" Grid.Column="1" Grid.Row="0" Width="140" />
                <TextBlock Text="Password" Grid.Column="0" Grid.Row="1"
                        Margin="2" VerticalAlignment="Center" />
                <!-- Yes, the password is visible in this example. Use a PasswordBox to mask the password text. -->
                <!--<PasswordBox Name="PasswordTextBox" HorizontalAlignment="Right" Margin="2" Grid.Column="1" Grid.Row="1" Width="140" />-->
                <TextBox Name="PasswordTextBox" Text="   " HorizontalAlignment="Right" Margin="2" Grid.Column="1" Grid.Row="1" Width="140" />
                <Button Name="LoginLoadLayerButton" Content="Login and Load Layer" Width="140" Margin="0,5,0,10" 
                        HorizontalAlignment="Center" Grid.Row="2" Grid.ColumnSpan="2" Click="LoginLoadLayerButton_Click" />

            </Grid>
        </Grid>
        <StackPanel  x:Name="EditorToolStrip" Margin="0,5,5,0" >
            <Border Background="#00919191" CornerRadius="5"
               HorizontalAlignment="Right"  VerticalAlignment="Top"
               Padding="5" BorderBrush="Transparent">
                <Border.Effect>
                    <DropShadowEffect Color="Black" Direction="-45" BlurRadius="20" Opacity=".75" />
                </Border.Effect>
                <StackPanel Orientation="Vertical" HorizontalAlignment="Right" Margin="0,5,5,0" VerticalAlignment="Top" >
                    <esri:EditorWidget x:Name="MyEditorWidget"
                             Map="{Binding ElementName=MyMap}" 
                                      Width="300" 
                                      AutoSelect="False"
                                      AlwaysDisplayDefaultTemplates="True" 
                                      GeometryServiceUrl="http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"
                                      ShowAttributesOnAdd="True"  
                                      Loaded="EditorWidget_Loaded"/>
                </StackPanel>
            </Border>
        </StackPanel>
           
    </Grid>
</UserControl>


using System.Windows.Controls;
using ESRI.ArcGIS.Client;
using System.Windows;
using System;
using System.Windows.Threading;

namespace Secure3
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }

   
        private void LoginLoadLayerButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            ESRI.ArcGIS.Client.TokenManager tokenManager = new ESRI.ArcGIS.Client.TokenManager()
            {
                UserName = UserTextBox.Text,
                Password = PasswordTextBox.Text,
                TokenSource = "https://XXXXXXX/arcgis/tokens",
                AutoRefreshing = true,
                Expiration = 5
            };

            tokenManager.RequestTokenCompleted += (s, a) =>
            {
                if (a.Error == null)
                {
                    LoginGrid.Visibility = System.Windows.Visibility.Collapsed;
                    MyMap.Layers.Add(new FeatureLayer()
                    {
                        Url = "http://XXXXXX/ArcGIS/rest/services/secure/Water_Utilites_Job_Log/FeatureServer/0",
                        Token = a.Token,
                        ID = "Job_Points"
                    });
                }
                else
                {
                    MessageBox.Show("Error: " + a.Error);
                }
            };
            tokenManager.RequestTokenAsync();
        }

        private void EditorWidget_Loaded(object sender, RoutedEventArgs e)
        {
            string[] myLayerIDs = { "Job_Points" };
            MyEditorWidget.LayerIDs = myLayerIDs;
        }      

    }
}


My server is running 10.0 SP 3, I dunno if that's a problem or not.

Thanks
0 Kudos
ChristopherHill
Deactivated User
You need to add OutFields to your FeatureLayer so that the attributes show up. Here is a basic Editing example with source code and xaml.
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#ToolkitEditorWidget
0 Kudos
JasonCleaver
Frequent Contributor
Any idea when v2.3 is scheduled for release?
0 Kudos
JenniferNery
Esri Regular Contributor
Did Chris' suggestion work for you?

If your FeatureLayer comes from a feature service with Editing-enabled in the Capabilties, you should be able to update with FeatureDataForm. http://help.arcgis.com/en/arcgisserver/10.0/help/arcgis_server_dotnet_help/index.html#/Feature_servi...

Do you see the Fields as read-only TextBoxes? If it is empty, you should set FeatureLayer.OutFields (as Chris suggested). Try putting "*" to show all fields.

We are wrapping up 2.3 Final but I cannot give a tentative release date.
0 Kudos
MattMiley
Deactivated User
Did Chris' suggestion work for you?


Yes it did!! Thanks Chris and Jennifer.
0 Kudos