Accessing the Bing Maps SOAP Services

 

This documentation is no longer available on MSDN. It is available as a CHM or PDF download. For the newest Geocoding, Imagery, Routing and Traffic services, see Bing Maps REST Services. 

The topic describes how to access the Bing Maps SOAP Services using a Bing Maps Key or a token.

You create and access Bing Maps Keys at the Bing Maps account For information about how to get a Bing Maps account and Bing Maps Keys, see Getting a Bing Maps Key.

To use the Bing Maps Key for your application, set the ApplicationId property of a Credentials object to your Bing Maps Key string. Then, use this object to set the Credentials property of the RequestBase Class. The following example shows how to set Bing Maps Key as part of a request to the Imagery service.

System_CAPS_noteNote

Whenever you use or display results returned from the Bing Maps SOAP Services, you need to also display the logo returned in the ResponseBase.BrandLogoUri Property and copyright notices returned in the ResponseSummary.Copyright Property.

private void RequestImage()
 {
 string Results="";
 try
 {
 // Set a Bing Maps key before making a request
 string key = "Bing Maps Key";

 ImageryService.MapUriRequest mapUriRequest = new ImageryService.MapUriRequest();

 // Set credentials using a valid Bing Maps Key
 mapUriRequest.Credentials = new ImageryService.Credentials();
 mapUriRequest.Credentials.ApplicationId  = key;

 // Set the location of the requested image
 mapUriRequest.Center = new ImageryService.Location();
 mapUriRequest.Center.Latitude = 47.65;
 mapUriRequest.Center.Longitude = -122.24;

 // Set the map style and zoom level
 ImageryService.MapUriOptions mapUriOptions = new ImageryService.MapUriOptions();
 mapUriOptions.Style = ImageryService.MapStyle.AerialWithLabels_v1;
 mapUriOptions.ZoomLevel = 10;

 // Set the size of the requested image to match the size of the image control
 mapUriOptions.ImageSize = new ImageryService.SizeOfint();
 mapUriOptions.ImageSize.Height = 400;
 mapUriOptions.ImageSize.Width = 600;

 mapUriRequest.Options = mapUriOptions;

 ImageryService.ImageryServiceClient imageryService =
   new ImageryService.ImageryServiceClient("BasicHttpBinding_IImageryService");

 // Make the image request
 ImageryService.MapUriResponse mapUriResponse = imageryService.GetMapUri(mapUriRequest);
 string mapUri = mapUriResponse.Uri;

 // Set the image control URL to the returned image URI
 Results = mapUri;

 }
 catch (Exception ex)
 {
 Results = "An exception occurred: " + ex.Message;

 }

 }



Private Sub RequestImage()
Dim Results As String
Try
' Set a Bing Maps key before making a request

Dim key = "Bing Maps Key"

Dim mapUriRequest As New ImageryService.MapUriRequest()

' Set credentials using a valid Bing Maps Key
mapUriRequest.Credentials = _
New ImageryService.Credentials() With {.ApplicationId = key}

' Set the location of the requested image
mapUriRequest.Center = _
New ImageryService.Location() With {.Latitude = 47.65, .Longitude = -122.24}

' Set the map style and zoom level
Dim mapUriOptions As New ImageryService.MapUriOptions() _
With {.Style = imageryService.MapStyle.AerialWithLabels_v1, .ZoomLevel = 10}

' Set the size of the requested image to match the size of the image control
mapUriOptions.ImageSize = New ImageryService.SizeOfint() _
With {.Height = 400, .Width = 600}

mapUriRequest.Options = mapUriOptions

Dim ImageryServiceInstance As New 
  ImageryService.ImageryServiceClient("BasicHttpBinding_IImageryService")

' Make the image request
Dim mapUriResponse = ImageryServiceInstance.GetMapUri(mapUriRequest)
Dim mapUri = mapUriResponse.Uri

' Set the image control URL to the returned image URI
Results = mapUri

Catch ex As Exception
Results = "An exception occurred: " & ex.Message
End Try

End Sub

System_CAPS_importantImportant

The Bing Maps Token Service will be retired on March 30, 2012. For information about upgrading your application to use Bing Maps Keys, see Migrating from Tokens to Keys.

If you are using the Bing Maps Token Service, set the Credentials.Token Property to a retrieved token before using a service method to make a request. Note that tokens expire and so new tokens need to be retrieved on a regular basis.

Show: