ArcGIS Runtime SDK for WPF - Library Reference
GetServiceInfoAsync Method
See Also  Example
ESRI.ArcGIS.Client.Printing Namespace > PrintTask Class : GetServiceInfoAsync Method

userToken
The user token.
Gets the service information PrintServiceInfo Raises the GetServiceInfoCompleted.

Syntax

Visual Basic (Declaration) 
Public Sub GetServiceInfoAsync( _
   Optional ByVal userToken As Object _
) 
C# 
public void GetServiceInfoAsync( 
   object userToken
)

Remarks

Discovering PrintTask Capabilities

It is possible to programmatically discover what capabilities are available for a particular PrintTask on an ArcGIS Server service using the PrintTask.GetServiceInfoAsync Method. When the PrintTask.GetServiceInfoAsync Method is called, ArcGIS Server returns an e.ServiceInfoEventArgs argument in the PrintTask.GetServiceInfoCompleted Event to provide the following information:

Argument Description
e.Error Error information (if any) for the PrintTask service.
e.ServiceInfo PrintServiceInfo Class that provides: return image formats, Layout Templates available, and whether the service is an 'asynchronous geoprocessing task' or a 'synchronous geoprocessing task'.
e.UserState A userToken unique identifier to track the PrintTask.GetServiceInfoAsync Method call.

Note: An example of programmatically discovering what capabilities are available for a particular PrintTask can be found in the example section of this document.

The same information in the e.ServiceInfo argument in the previous table can also found by examining the ArcGIS REST Services Directory for the PrintTask.Url (see the following screen shot):

The ArcGIS Rest Services Directory can show the same information as the PrintServiceInfo Class members.

Parameters

userToken
The user token.

Example

How to use:

Supply a valid Url for a PrintTask in the TextBox and then click the 'GetServiceInfoAsync' Button. Details about the PrintTask via the PrintServiceInfo Class will be returned, specifically: if there are any errors with the service, whether it is an asynchronous (true) or synchronous (false) geoprocesing PrintTask, which return image format types are supported, and what types of Layout Templates are supported to generate a return Map image. Note: a Map Control (with Layers) is not necessary for this example since we are just trying to obtain details about the PrintTask service.

The XAML code in this example is used in conjunction with the code-behind (C# or VB.NET) to demonstrate the functionality.

The following screen shot corresponds to the code example in this page.

Using the PrintTask.GetServiceInfoAsync Method to determine information about the PrintTask service.

XAMLCopy Code
<Grid x:Name="LayoutRoot" Background="White">
  
  <!-- Url of the PrintTask. -->
  <sdk:Label Height="18" HorizontalAlignment="Left" Margin="0,100,0,0" Name="Label_Url" 
             VerticalAlignment="Top" Width="31" Content="Url:"/>
  <TextBox Height="23" HorizontalAlignment="Left" Margin="0,118,0,0" Name="TextBox_Url" 
           VerticalAlignment="Top" Width="600" FontSize="10" />
    
  <!-- Button to perform the work. -->
  <Button Content="GetServiceInfoAsync" Height="23" Width="161" HorizontalAlignment="Left" Margin="427,91,0,0" 
          Name="Button_GetServiceInfoAsync" VerticalAlignment="Top" Click="Button_GetServiceInfoAsync_Click" />
  
  <!-- BaseEventArgs.Error messages. -->
  <sdk:Label Height="18" HorizontalAlignment="Left" Margin="0,157,0,0" Name="Label_BaseEventArgs_Error" 
             Content="BaseEventArgs.Error:" VerticalAlignment="Top" Width="138" />
  <TextBox Height="23" HorizontalAlignment="Left" Margin="0,175,0,0" Name="TextBox_BaseEventArgs_Error" 
           VerticalAlignment="Top" Width="600" />
  
  <!--PrintServiceInfo.IsServiceAsynchronous (True = asynchronous geoprocessing task | False = synchronous geoprocessing task). -->
  <sdk:Label Height="18" HorizontalAlignment="Left" Margin="0,218,0,0" Name="Label_PrintServiceInfo_IsServiceAsynchronous" 
             VerticalAlignment="Top" Width="254" Content="PrintServiceInfo.IsServiceAsynchronous:"/>
  <TextBox Height="30" HorizontalAlignment="Left" Margin="0,234,0,0" Name="TextBox_PrintServiceInfo_IsServiceAsynchronous" 
           VerticalAlignment="Top" Width="600" />
  
  <!-- PrintServiceInfo.Formats (for the images returned from ArcGIS Server). -->
  <sdk:Label Height="18" HorizontalAlignment="Left" Margin="0,282,0,0" Name="Label_PrintServiceInfo_Formats" 
             Content="PrintServiceInfo_Formats:" VerticalAlignment="Top" Width="160" />
  <TextBox Height="251" HorizontalAlignment="Left" Margin="0,302,0,0" Name="TextBox_PrintServiceInfo_Formats" 
           VerticalAlignment="Top" Width="290" />
    
  <!-- PrintServiceInfo.LayoutTemplates (the Layout Template ArcGIS Server uses to render the return image). -->
  <sdk:Label Height="18" HorizontalAlignment="Left" Margin="310,284,0,0" Name="Label_PrintServiceInfo_LayoutTemplates" 
             VerticalAlignment="Top" Width="206" Content="PrintServiceInfo_LayoutTemplates:"/>
  <TextBox Height="251" HorizontalAlignment="Left" Margin="310,302,0,0" Name="TextBox_PrintServiceInfo_LayoutTemplates" 
           VerticalAlignment="Top" Width="290" />
  
  <!-- Provide the instructions on how to use the sample code. -->
  <TextBlock Height="94" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="612" 
       TextWrapping="Wrap" Text="Supply a valid Url for a PrintTask in the TextBox and then click the 
       'GetServiceInfoAsync' Button. Details about the PrintTask via the PrintServiceInfo Class will be 
       returned, specifically: if there are any errors with the service, whether it is an asynchronous (true) 
       or synchronous (false) geoprocesing PrintTask, which return image format types are supported, and what 
       types of Layout Templates are supported to generate a return Map image. Note: a Map Control (with Layers) 
       is not necessary for this example since we are just trying to obtain details about the PrintTask service." />
            
</Grid>
C#Copy Code
// Create a Global (aka. Member) variable for the PrintTask object that will be used in other 
// parts of the application.
private ESRI.ArcGIS.Client.Printing.PrintTask _PrintTask;
            
public MainPage()
{
  InitializeComponent();
  
  // Provide a valid PrintTask.Url (either an 'asynchronous geoprocessing task' or 
  // 'synchronous geoprocessing task' will work).
  TextBox_Url.Text = "http://localhost:6080/arcgis/rest/Utilties/PrintingTools/GPServer/Export20Web20Map%20Task";
  
  // Set the _PrintTask variable to a new instance of the PrintTask Class.
  _PrintTask = new ESRI.ArcGIS.Client.Printing.PrintTask();
  
  // Wire up an Event Handler for the PrintTask.GetServiceInfoCompleted Event.
  _PrintTask.GetServiceInfoCompleted += printTask_GetServiceInfoCompleted;
}
            
private void Button_GetServiceInfoAsync_Click(object sender, System.Windows.RoutedEventArgs e)
{
  // Set the PrintTask.Url from what is entered in the TextBox.
  _PrintTask.Url = TextBox_Url.Text;
  
  // Call the PrintTask.GetServiceInfoAsync Method to find out what the capabilities of the PrintTask are.
  _PrintTask.GetServiceInfoAsync();
}
            
private void printTask_GetServiceInfoCompleted(object sender, ESRI.ArcGIS.Client.Printing.ServiceInfoEventArgs e)
{
  // Get any error information about the PrintTask.
  System.Exception theException = e.Error;
  
  if (theException != null)
  {
    // User TODO: More could be done to interrogate the Error and take appropriate action.
    TextBox_BaseEventArgs_Error.Text = theException.Message;
  }
  else
  {
    // No error occured.
    TextBox_BaseEventArgs_Error.Text = "No Exception Errors were thrown.";
  }
  
  // Get the print service information about the PrintTask.
  ESRI.ArcGIS.Client.Printing.PrintServiceInfo thePrintServiceInfo = e.ServiceInfo;
  
  if (thePrintServiceInfo != null)
  {
    // We have PrintServiceInfo results, display them.
    
    // Tell whether we have an asynchronous (true) or synchronous (false) geoprocesing PrintTask.
    bool theIsServiceAsynchronous = thePrintServiceInfo.IsServiceAsynchronous;
    TextBox_PrintServiceInfo_IsServiceAsynchronous.Text = theIsServiceAsynchronous.ToString();
    
    // Get the image formats available that can be generated on ArcGIS Server and display in a ListBox.
    System.Collections.Generic.IEnumerable<string> theFormats = thePrintServiceInfo.Formats;
    Text.StringBuilder sbFormats = new Text.StringBuilder();
    foreach (string theFormat in theFormats)
    {
      sbFormats.Append(theFormat + Environment.NewLine);
    }
    TextBox_PrintServiceInfo_Formats.Text = sbFormats.ToString();
    
    // Get the Layouts availble that can be used to generate maps and display in a ListBox.
    System.Collections.Generic.IEnumerable<string> theLayoutTemplates = thePrintServiceInfo.LayoutTemplates;
    Text.StringBuilder sbLayoutTemplates = new Text.StringBuilder();
    foreach (string theLayoutTemplate in theLayoutTemplates)
    {
      sbLayoutTemplates.Append(theLayoutTemplate + Environment.NewLine);
    }
    TextBox_PrintServiceInfo_LayoutTemplates.Text = sbLayoutTemplates.ToString();
  }
  else
  {
    // There is no PrintServiceInfo. Most likely we also have an e.Error as well.
    TextBox_PrintServiceInfo_Formats.Text = "No PrintServiceInfo.Formats returned.";
    TextBox_PrintServiceInfo_IsServiceAsynchronous.Text = "No PrintServiceInfo.IsServiceAsynchronous returned.";
    TextBox_PrintServiceInfo_LayoutTemplates.Text = "No PrintServiceInfo.LayoutTemplates returned.";
  }
}
VB.NETCopy Code
' Create a Global (aka. Member) variable for the PrintTask object that will be used in other 
' parts of the application.
Private _PrintTask As ESRI.ArcGIS.Client.Printing.PrintTask
  
Public Sub New()
  InitializeComponent()
  
  ' Provide a valid PrintTask.Url (either an 'asynchronous geoprocessing task' or 
  ' 'synchronous geoprocessing task' will work).
  TextBox_Url.Text = "http://localhost:6080/arcgis/rest/Utilties/PrintingTools/GPServer/Export20Web20Map%20Task"
  
  ' Set the _PrintTask variable to a new instance of the PrintTask Class.
  _PrintTask = New ESRI.ArcGIS.Client.Printing.PrintTask()
  
  ' Wire up an Event Handler for the PrintTask.GetServiceInfoCompleted Event.
  AddHandler _PrintTask.GetServiceInfoCompleted, AddressOf printTask_GetServiceInfoCompleted
  
End Sub
            
Private Sub Button_GetServiceInfoAsync_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
  
  ' Set the PrintTask.Url from what is entered in the TextBox.
  _PrintTask.Url = TextBox_Url.Text
  
  ' Call the PrintTask.GetServiceInfoAsync Method to find out what the capabilities of the PrintTask are.
  _PrintTask.GetServiceInfoAsync()
  
End Sub
            
Private Sub printTask_GetServiceInfoCompleted(sender As Object, e As ESRI.ArcGIS.Client.Printing.ServiceInfoEventArgs)
  
  ' Get any error information about the PrintTask.
  Dim theException As System.Exception = e.Error
  
  If theException IsNot Nothing Then
    
    ' User TODO: More could be done to interrogate the Error and take appropriate action.
    TextBox_BaseEventArgs_Error.Text = theException.Message
    
  Else
    
    ' No error occured.
    TextBox_BaseEventArgs_Error.Text = "No Exception Errors were thrown."
    
  End If
  
  ' Get the print service information about the PrintTask.
  Dim thePrintServiceInfo As ESRI.ArcGIS.Client.Printing.PrintServiceInfo = e.ServiceInfo
  
  If thePrintServiceInfo IsNot Nothing Then
    
    ' We have PrintServiceInfo results, display them.
    
    ' Tell whether we have an asynchronous (true) or synchronous (false) geoprocesing PrintTask.
    Dim theIsServiceAsynchronous As Boolean = thePrintServiceInfo.IsServiceAsynchronous
    TextBox_PrintServiceInfo_IsServiceAsynchronous.Text = theIsServiceAsynchronous.ToString
    
    ' Get the image formats availble that can be generated on ArcGIS Server and display in a ListBox.
    Dim theFormats As System.Collections.Generic.IEnumerable(Of String) = thePrintServiceInfo.Formats
    Dim sbFormats As New Text.StringBuilder
    For Each theFormat As String In theFormats
      sbFormats.Append(theFormat + vbCrLf)
    Next
    TextBox_PrintServiceInfo_Formats.Text = sbFormats.ToString
    
    ' Get the Layouts available that can be used to generate maps and display in a ListBox.
    Dim theLayoutTemplates As System.Collections.Generic.IEnumerable(Of String) = thePrintServiceInfo.LayoutTemplates
    Dim sbLayoutTemplates As New Text.StringBuilder
    For Each theLayoutTemplate As String In theLayoutTemplates
      sbLayoutTemplates.Append(theLayoutTemplate + vbCrLf)
    Next
    TextBox_PrintServiceInfo_LayoutTemplates.Text = sbLayoutTemplates.ToString
    
  Else
    
    ' There is no PrintServiceInfo. Most likely we also have an e.Error as well.
    TextBox_PrintServiceInfo_Formats.Text = "No PrintServiceInfo.Formats returned."
    TextBox_PrintServiceInfo_IsServiceAsynchronous.Text = "No PrintServiceInfo.IsServiceAsynchronous returned."
    TextBox_PrintServiceInfo_LayoutTemplates.Text = "No PrintServiceInfo.LayoutTemplates returned."
    
  End If
  
End Sub

Requirements

Target Platforms: Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family, Windows 7, Windows 8

See Also

© ESRI, Inc. All Rights Reserved.