You are here: Using SOAP > v2006 services > Tutorials and samples > Using Visual Studio 2003 C#.NET v2006

T U T O R I A L

Using Visual Studio C# .NET 2003 with ArcWeb Services v2006

The purpose of this quick-start tutorial is to demonstrate how to access ArcWeb Services using Microsoft Visual Studio C#.NET. .NET is a Web service development package that supports several programming languages including VB and C#. This tutorial assumes you have Visual Studio .NET 2003 running on your machine and an activated ArcWeb account.

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 an validation token prior to accessing an 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.

Overview

Download the sample code.

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 user. Use this token to access Address Finder Web Service.

In the second request, you call Address Web Finder 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 match the input argument.

How to use

  1. Open Visual Studio 2003.
  2. Click File, click New, and select Project.
  3. Click Visual C# Projects under Project types, then click Console Application under Templates.
  4. Copy and paste the sample code below within your class (Class 1). This replaces the Main method. NOTE: The downloadable ZIP file contains the same sample code.
static void Main(string[] args)
{


string username = "USERNAME" ; //Replace with your ArcWeb usernamestring password = "PASSWORD" ; // Replace with your ArcWeb Passwordint expiration = 60 ; //  minutes until the token expires (expiration) try { // Create an instance of Authentication.Authentication authentication = new Authentication();
// Create an instance of AddressFinder.AddressFinder addressFinder = new 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.Address address = new Address(); address.houseNumber = "380" ; address.street = "NewYork street"; address.intersection = ""; address.city= "Redlands"; address.stateProvince = "CA"; address.country= "US";
//AddressFinderOptionAddressFinderOptions addressFinderOptions=new AddressFinderOptions (); addressFinderOptions.dataSource ="ArcWeb:TA.Streets.US";
//------------Call AddressFinder service -------------- GeocodeInfo geocodeInfo = addressFinder.findLocationByAddress(address,addressFinderOptions,token);
//------------Print the results--------------GeocodeCandidate[] candidates = geocodeInfo.candidates; // Print x,y coordiates of first candidateConsole.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
  1. Replace [username] and [password] with your ESRI Global Account user name and password. NOTE: Your account must be activated for ArcWeb Services.
  2. Add a Web reference for the Authentication Web Service to the new console application. This step creates a proxy class on the client computer. After the proxy class exists, you can create objects based on the class. Each method call that is made with the object then goes out to the URL of the ArcWeb Service, usually as a SOAP request.
    1. Click Project and click Add Web Reference.
    2. In the Add Web Reference dialog box, type the URL for the Authentication Web Service in the Address text box (https://www.arcwebservices.com/services/v2006/Authentication.wsdl) and press Enter.
    1. Click Add Reference.
  1. Repeat Step 6 for Address Finder Web Service (http://www.arcwebservices.com/services/v2006/AddressFinder.wsdl)
  2. Include a "using" directive for each of the namespaces of AddressFinder and Authentication in your Console Application. 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.com.esri.arcwebservices.www ;

  1. Click Build on the Build menu to build the console application.
  2. Click Debug and click Start to test the application.
  1. Save and close the project.

Visit the Feedback page to give comments or suggestions about the ArcWeb Developer's Guide.

ArcWeb site | ArcWeb support | support.esri.com

Copyright © ESRI