The purpose of this quick-start tutorial is to demonstrate how to access ArcWeb Services using Microsoft Visual Studio VB.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 VB.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.
|
|
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.
Module Module1
Sub Main()
Dim username = "USERNAME" 'Replace with your ArcWeb usernameDim password = "PASSWORD" 'Replace with your ArcWeb PasswordDim expiration = 60
Try 'Create an instance of the AuthenticationDim AuthenticationInstance As Authentication AuthenticationInstance = New Authentication
'Create an instance of the AddressFinderDim AddressFinderInstance As AddressFinder AddressFinderInstance = New AddressFinder
'Request a token from the Authentication Web Service Dim token As String
'---------------Call the Authentication Web Service ----------------- token = AuthenticationInstance.getCustomExpirationToken(username, password, expiration)
'Create an instance of Address, the definition of the address or intersection to be located.Dim myAddress As Address myAddress = New Address myAddress.houseNumber = "380" myAddress.street = "NewYork Street" myAddress.city = "Redlands" myAddress.stateProvince = "CA" myAddress.postalCode = "92373" myAddress.country = "US"
'Create an instance of AddressFinderOptions Dim myAddressFinderOptions As New AddressFinderOptions myAddressFinderOptions.dataSource = "ArcWeb:TA.Streets.US"
'---------------Call the AddressFinder Web Service - findLocationByAddress method-----------Dim myGeocodeInfo As New GeocodeInfo myGeocodeInfo = AddressFinderInstance.findLocationByAddress(myAddress, myAddressFinderOptions, token)
'--------------- Display the results from the Web service------------Dim myGeocodeCandidate As GeocodeCandidate
' Get the first candidate from the resultmyGeocodeCandidate = myGeocodeInfo.candidates(0)
' Print the resultConsole.WriteLine(myGeocodeCandidate.desc1) 'Address description1 Console.WriteLine("(" + (myGeocodeCandidate.point.x).ToString + "," + (myGeocodeCandidate.point.y).ToString + " ) ") ' Lon/lat of addressConsole.WriteLine("Match Type = " + myGeocodeCandidate.matchType) ' Address MatchType Console.ReadLine() ' Does nothing
Catch e As Exception ' print any exception
Console.WriteLine(e.Message) Console.ReadLine() ' Does nothing
End Try
End Sub
End Module
Imports ConsoleApplication1.com.esri.arcweb
Visit the Feedback page to give comments or suggestions about the ArcWeb Developer's Guide.