[Visual Basic .NET]Sub GeocodeAddressClientAgainstServer() Dim connectionProperties = New PropertySet connectionProperties.SetProperty("Machine", "AGSServer") Dim serverConnectionFactory As IAGSServerConnectionFactory = New AGSServerConnectionFactory Dim agsServerConnection As IAGSServerConnection = serverConnectionFactory.Open(connectionProperties, 0) Dim serverObjectNames As IAGSEnumServerObjectName = agsServerConnection.ServerObjectNames serverObjectNames.Reset() ' Get the GeocodeServer service information Dim name As IName Dim geocodeServer As IGeocodeServer Dim serverObject As IAGSServerObject Dim serverObjectName As IAGSServerObjectName = serverObjectNames.Next() While Not serverObjectName Is Nothing ' UnitedStates is a locator published to ArcGIS Server in a Geocode folder If serverObjectName.Name = "Geocode/UnitedStates" And serverObjectName.Type = "GeocodeServer" Then name = serverObjectName serverObject = name.Open() If Not serverObject Is Nothing Then geocodeServer = serverObject Exit While End If End If serverObjectName = serverObjectNames.Next() End While ' Set the Address Properties and Geocode the address Dim fields As IFields = geocodeServer.GetAddressFields() Dim addressProperties As IPropertySet = New PropertySet addressProperties.SetProperty(fields.Field(0).Name, "9300 Cherry Ave") addressProperties.SetProperty(fields.Field(1).Name, "Fontana") addressProperties.SetProperty(fields.Field(2).Name, "CA") addressProperties.SetProperty(fields.Field(3).Name, "92335") Dim addressResultProperties As IPropertySet = geocodeServer.GeocodeAddress(addressProperties, Nothing) End Sub
[C#]public void GeocodeAddressClient() { IPropertySet connectionProperties = new PropertySet(); connectionProperties.SetProperty("Machine", "AGSServer"); // Create a connection to the ArcGIS Server Type t = Type.GetTypeFromProgID("esriGISClient.AGSServerConnectionFactory"); System.Object obj = Activator.CreateInstance(t); IAGSServerConnectionFactory serverConnectionFactory = obj as AGSServerConnectionFactory; IAGSServerConnection agsServerConnection = serverConnectionFactory.Open(connectionProperties, 0); IAGSEnumServerObjectName serverObjectNames = agsServerConnection.ServerObjectNames; serverObjectNames.Reset(); // Get the GeocodeServer service information IName name; IGeocodeServer geocodeServer = null; IAGSServerObject serverObject = null; IAGSServerObjectName serverObjectName = serverObjectNames.Next(); while (serverObjectName != null) { // California is a locator published to ArcGIS Server in a Geocode folder if (serverObjectName.Name == "Geocode/California" && serverObjectName.Type == "GeocodeServer") { name = serverObjectName as IName; serverObject = name.Open() as IAGSServerObject; if (serverObject as IGeocodeServer != null) { geocodeServer = serverObject as IGeocodeServer; break; } } serverObjectName = serverObjectNames.Next(); } // Set up the address properties and geocode the address IFields fields = geocodeServer.GetAddressFields(); IPropertySet addressProperties = new PropertySetClass(); addressProperties.SetProperty(fields.get_Field(0).Name, "9300 Cherry Ave"); addressProperties.SetProperty(fields.get_Field(1).Name, "Fontana"); addressProperties.SetProperty(fields.get_Field(2).Name, "CA"); addressProperties.SetProperty(fields.get_Field(3).Name, "92335"); IPropertySet addressResultProperties = geocodeServer.GeocodeAddress(addressProperties, null); }