The purpose of this quick-start tutorial is to demonstrate how to access ArcWeb Services with C#.Net using Microsoft Visual Studio 2005.
The sample uses Authentication Web Service and Address Finder Web Service as examples of how to use C#.NET to call ArcWeb Services. ArcWeb Authentication Web Service requires that you send it a request for a validation token prior to accessing any ArcWeb service. You then use this returned token to send your geocoding request to Address Finder Web Service. In this sample, a user enters a series of addresses to be geocoded until the authentication token expires, at which point the client requests a new token from the Authentication Web Service.
This tutorial assumes you have the following:
The following steps guide you through sending two requests to ArcWeb Services.
In the first request, you call Authentication Web Service with the following method:
getCustomExpirationToken(username:string, password:string, expiration:integer):string
Included in your request is your user name (username), password (password), and the minutes until the token should expire (expiration). Authentication Web Service returns a token (string) that validates you as an authorized ArcWeb Services user. Use this token to access Address Finder Web Service.
In the second request, you call Address Finder Web Service with the following method:
findLocationByAddress(address:Address, addressFinderOptions:AddressFinderOptions, token:string):GeocodeInfo
Included in your request are two objects (Address and AddressFinderOptions) and the token from the Authentication Web Service. Address Finder Web Service returns a list of geocoded matches for the address that correspond to the input argument.
NOTE: The downloadable ZIP file contains the same sample code.
using System;
using Au = ConsoleApplication1.Authentication;
using Af = ConsoleApplication1.AddressFinder;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string username = "USERNAME"; //Replace with your ESRI Global Account user name
string password = "PASSWORD"; // Replace with your ESRI Global Account password
int expiration = 60; // minutes until the token expires (expiration)
try
{
// Create an instance of Authentication.
Au.Authentication authentication = new Au.Authentication();
// Create an instance of AddressFinder.
Af.AddressFinder addressFinder = new Af.AddressFinder();
//---------Call Authentication Web Service ---------------
string token = authentication.getCustomExpirationToken(username, password, expiration);
//Create an instance of Address - which is the definition of the address or intersection.
Af.Address address = new Af.Address();
address.houseNumber = "380";
address.street = "NewYork street";
address.intersection = "";
address.city = "Redlands";
address.stateProvince = "CA";
address.country = "US";
//AddressFinderOption
Af.AddressFinderOptions addressFinderOptions = new Af.AddressFinderOptions();
addressFinderOptions.dataSource = "ArcWeb:TA.Streets.US";
//------------Call AddressFinder service --------------
Af.GeocodeInfo geocodeInfo = addressFinder.findLocationByAddress(address, addressFinderOptions, token);
//------------Print the results--------------
Af.GeocodeCandidate[] candidates = geocodeInfo.candidates;
// Print x,y coordinates of first candidate
Console.WriteLine(candidates[0].desc1 + " (" + candidates[0].point.x + "," + candidates[0].point.y + ")");
Console.WriteLine("Match Type = " + candidates[0].matchType);
Console.ReadLine();
}
catch (System.Web.Services.Protocols.SoapException e)
{
Console.WriteLine(e.Message);
Console.ReadLine();
}
} //main
}
}
NOTE: Your account must be activated for ArcWeb Services.
NOTE: You may receive the following warning: "Schema validation warning: Schema item 'complexType' named 'GeocodeCandidate' from namespace 'http://www.arcwebservices.com/v2006_1/com.esri.aws.dto/' is invalid. Namespace 'http://www.arcwebservices.com/v2006_1/com.esri.aws.dto.geom/' is not available to be referenced in this schema." This warning does not affect the functionality of either service and the AddressFinder and Authentication services will work without problems.
HINT: You can see the names of the namespaces in Class View (View > Class View). Use the format: Using [project name].[namespace], for example:
using ConsoleApplication1.Authentication
Visit the Feedback page to give comments or suggestions about the ArcWeb Developer's Guide.