Connects the ServiceLayer to spatial data provided by a service: ArcGIS Server (map, globe and image), ArcIMS, WMS or Bing maps.

Namespace:  ESRI.ArcGISExplorer.Mapping

Assembly:  ESRI.ArcGISExplorer (in ESRI.ArcGISExplorer.dll) Version: 2.0.0.1500 (2.0.0.1500)

Syntax

C#
public override bool Connect()
Visual Basic (Declaration)
Public Overrides Function Connect As Boolean

Return Value

trueTruetruetrue (True in Visual Basic) if the ServiceLayer was connected successfully; otherwise falseFalsefalsefalse (False in Visual Basic)

Remarks

In order for ServiceLayer data to be displayed on a map, the layer must be in a connected state. Use this method to establish a connection to the ServiceLayer data source.

A ServiceLayer references spatial data provided by a service. Use the parameterized constructor or the ServiceConnectionProperties property to specify the data source for the layer. If the connection properties specified are incorrect, the Layer will remain disconnected but no exception will be thrown; use the ConnectionStatus property to diagnose why the Layer could not be connected.

Examples

The code below demonstrates two different approaches to creating a ServiceLayer for an ArcGIS Server globe service. In the first example a ServiceLayer object is created using the connection information specified in a ServiceConnectionProperties object, then connected manually using the Connect method. In contrast, the second example shows how to both create and connect a ServiceLayer in a single call using the static OpenGlobeServer method.
CopyC#
{
  //Example 1 - Instantiate a ServiceLayer and connect explicitly.
  //**************************************************************

  //Define the connection properties to the Surface subservice in the NASA_Cloudcover_World globe service
  ServiceConnectionProperties connProps = new ServiceConnectionProperties(ServiceType.GlobeServer,
                                               new Uri("http://services.arcgisonline.com/arcgis/services"),
                                               "NASA_Cloudcover_World",
                                               "Surface");

  //Create a new ServiceLayer
  ServiceLayer serviceLayer1 = new ServiceLayer(connProps);

  //Set the layer name
  serviceLayer1.Name = "Clouds 1";

  //Try to connect the layer to the service
  bool connected = serviceLayer1.Connect();

  //Check to see whether the connection was successful
  if (connected)
  {
    //Add the layer to the map.
    ESRI.ArcGISExplorer.Application.Application.ActiveMapDisplay.Map.ChildItems.Add(serviceLayer1);
  }
  else
  {
    //Investigate connection issue.
    ConnectionStatus status = serviceLayer1.ConnectionStatus;
    if (status.HasError)
    {
      System.Diagnostics.Debug.Print(status.ErrorString);
    }
  }

  //Example 2 - Instantiate and connect with a single method call.
  //**************************************************************
  try
  {
    //Create a new service layer and connect it to the Surface subservice of the NASA_Cloudcover_World globe service
    ServiceLayer serviceLayer2 = ServiceLayer.OpenGlobeServer(new Uri("http://services.arcgisonline.com/arcgis/services"),
                                                                                     "NASA_Cloudcover_World", "Surface");

    //Set the layer name
    serviceLayer2.Name = "Clouds 2";

    //Add the layer to the map
    ESRI.ArcGISExplorer.Application.Application.ActiveMapDisplay.Map.ChildItems.Add(serviceLayer2);
  }
  catch (ESRI.ArcGISExplorer.ConnectionException ex)
  {
    System.Diagnostics.Debug.Print(ex.Message);
  }
}
CopyVB.NET
'Example 1 - Instantiate a ServiceLayer and connect explicitly.
'**************************************************************


'Define the connection properties to the Surface subservice in the NASA_Cloudcover_World globe service
Dim connProps As ServiceConnectionProperties = New ServiceConnectionProperties(ServiceType.GlobeServer, _
                                              New Uri("http://services.arcgisonline.com/arcgis/services"), _
                                              "NASA_Cloudcover_World", "Surface")

'Create a new ServiceLayer
Dim serviceLayer1 As ServiceLayer = New ServiceLayer(connProps)

'Set the layer name
serviceLayer1.Name = "Clouds 1"

'Try to connect the layer to the service
Dim connected As Boolean = serviceLayer1.Connect()

'Check to see whether the connection was successful
If (connected) Then
  'Add the layer to the map.
  ESRI.ArcGISExplorer.Application.Application.ActiveMapDisplay.Map.ChildItems.Add(serviceLayer1)
Else
  'Investigate connection issue.
  Dim status As ConnectionStatus = serviceLayer1.ConnectionStatus
  If status.HasError Then
    System.Diagnostics.Debug.Print(status.ErrorString)
  End If
End If

'Example 2 - Instantiate and connect with a single method call.
'**************************************************************
Try
  'Create a new service layer and connect it to the Surface subservice of the NASA_Cloudcover_World globe service
  Dim serviceLayer2 As ServiceLayer = ServiceLayer.OpenGlobeServer(New Uri("http://services.arcgisonline.com/arcgis/services"), _
                                                                                     "NASA_Cloudcover_World", "Surface")

  'Set the layer name
  serviceLayer2.Name = "Clouds 2"

  'Add the layer to the map
  ESRI.ArcGISExplorer.Application.Application.ActiveMapDisplay.Map.ChildItems.Add(serviceLayer2)
Catch ex As ESRI.ArcGISExplorer.ConnectionException
  System.Diagnostics.Debug.Print(ex.Message)
End Try

See Also