MapTP Web Services for Visual C# .NET Client Applications
Download client stubs and wrapper classes: map24wsclientscsharp.zip (89 KB)
Follow the instructions below for an easy start with MapTP Web Services. One way to create Web service client applications is by using client stubs that are generated from WSDLs. This is not the only way but it is common and fairly straight forward. Stubs can be generated with the wsdl tool that is provided with Visual Studio. You can download client stubs of the most recent WSDLs for some of the MapTP Web Services as zip file (see link above). The zip file also contains project files for Visual Studio that contain demo clients for the MapTP Geocoder Service, MapTP Maplet Remote Control Service, MapTP Routing Service, MapTP ReverseGeocoder Service, and MapTP MGI Service. Follow the steps in the Getting Started section below to run a demo client.
Getting Started
Prerequisites: Microsoft Visual Studio C# 2005 (Express Edition is OK, too)
Follow the steps described here to run the demo client for the MapTP Geocoder Service that is contained in the map24wsclientscsharp.zip file. This demo application sends a geocoding request to the MapTP Web Services and prints out the geocoded addresses:
- Download the client stubs and demo projects:
map24wsclientscsharp.zip
- Unzip the file.
- Open the demo project. The demo project is contained in the Map24Geocoder51 directory.
- Edit the client stub for the MapTP Geocoder 5.1 Service ('Map24Geocoder51.cs').
- In the Map24Geocoder51 constructor replace the MapTP server URL parameter with the URL that you received with your MapTP ID.
- Edit the demo application ('Map24Geocoder51Client.cs') shown in the code listing below.
- Specify your MapTP ID in the RequestHeader.Map24ID parameter.
- Specify the search text in SearchRequest.SearchText. The default search text might not fit to your map region.
- Build and run the client. The result is printed to the console.
Demo application:
namespace Com.Mapsolute.Webservices.Map24Geocoder51 {
using System; using System.IO; public class Map24Geocoder51Client { public static void Map24Geocoder51() { bool permit = true;
try { RequestHeader RequestHeader = new RequestHeader(); RequestHeader.Map24ID = "Your MapTPID goes here"; Map24Geocoder51 Map24Geocoder51 = new Map24Geocoder51();
if (permit) // freeSearchRequest { Console.WriteLine("Map24Geocoder51() SearchFreeRequest"); // create request MapSearchFreeRequest SearchRequest = new MapSearchFreeRequest(); SearchRequest.SearchText = "Crissy Field San Francisco"; SearchRequest.MaxNoOfAlternatives = 3;
// make request to server MapSearchResponse Response = Map24Geocoder51.searchFree( RequestHeader, SearchRequest);
// show response on console Console.WriteLine("Alternatives " + Response.Alternatives.GetLength(0)); int iAlt = Response.Alternatives.GetLength(0); // loop through all alternatives for (int j = 0; j < iAlt; j++) { Console.WriteLine("Alternative : " + j); Console.WriteLine("Longitude : " + Response.Alternatives[j].Coordinate.Longitude); Console.WriteLine("Latitude : " + Response.Alternatives[j].Coordinate.Latitude); int iMax = Response.Alternatives[j].PropertiesMajor.GetLength(0); // loop through address properties for (int i = 0; i < iMax; i++) { Console.WriteLine( Response.Alternatives[j].PropertiesMajor[i].Key + " : " + Response.Alternatives[j].PropertiesMajor[i].Value); } } } catch(Exception e) { Console.Error.WriteLine(e); } } public static int Main(){ Map24Geocoder51(); return 0; } } }
Generating Client Stubs
You can generate the client stubs yourself. This is necessary if you want to use one of the previous versions of the MapTP Web Services' WSDL.
Notes for Creating new Projects in Visual Studio
The Visual Studio projects that come in the provided zip file are all configured with the two things described below.
Reference System.Web.Service
If you create a new project with Visual Studio don't forget to add the references 'System.Web' and 'System.Web.Services'.
Work around HTTP 400 Bad Request Errors
If you are getting an HTTP 400 bad request error when debugging in Visual Studio add an app.config file with the switch Remote.Disable with value = 1 to your project. Here is why and how to do it:
To be able to send requests to the MapTP Web Services you have to add a file called "app.config" to your Visual C# .NET or Visual Basic .NET project. Then you can work in your project using all debugging resources (breakpoints, watches, etc.). This file must contain the following:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.diagnostics> <switches> <add name="Remote.Disable" value="1"/> </switches> </system.diagnostics> </configuration>
If you do not include this file you might see a "HTTP status 400: bad request" error when sending requests to the MapTP Web Services. This is a known problem in Microsoft Visual Studio. The .NET debugger attaches so-called "debug causality data" to each outgoing request. This data is used for debugging. However, this data destroys the well-formedness of the request and as a consequence the MapTP server returns an error.
|