void webclient_OpenReadCompleted(object sender, ArcGISWebClient.OpenReadCompletedEventArgs e)
{
try
{
if (e.Error != null)
throw new Exception(e.Error.Message);
// Deserialize response using classes defined by a data contract, included in this class definition below
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(MySvcs));
MySvcs mysvcs = serializer.ReadObject(e.Result) as MySvcs;
if (mysvcs.Services.Count == 0)
throw new Exception("No services returned");
// Use LINQ to return all map services
var mapSvcs = from s in mysvcs.Services
where s.Type == "MapServer"
select s;
// If map services are returned, show the Listbox with items as map services
if (mapSvcs.Count() > 0)
{
MySvcTreeView.ItemsSource = mapSvcs;
MySvcTreeView.Visibility = System.Windows.Visibility.Visible;
NoMapServicesTextBlock.Visibility = System.Windows.Visibility.Collapsed;
}
else
{
MySvcTreeView.Visibility = System.Windows.Visibility.Collapsed;
NoMapServicesTextBlock.Visibility = System.Windows.Visibility.Visible;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (e.Result != null)
e.Result.Close();
}
}