/// <summary> /// Creates a new instance of the <see cref="WorldGeocoder"/> class for the specified /// service configuration. /// </summary> /// <param name="serviceInfo">The instance of the geocoding service configuration /// specifying World geocoder service to create geocoder for.</param> /// <param name="exceptionHandler">Exception handler.</param> /// <returns>A new instance of the <see cref="WorldGeocoder"/> class.</returns> /// <exception cref="System.ArgumentNullException"><paramref name="serviceInfo"/> is a null /// reference.</exception> public static GeocoderBase CreateWorldGeocoder(GeocodingServiceInfo serviceInfo, IServiceExceptionHandler exceptionHandler) { CodeContract.RequiresNotNull("serviceInfo", serviceInfo); // Create binding for the geocoder REST service. var webBinding = ServiceHelper.CreateWebHttpBinding("WorldGeocoder"); var binding = new CustomBinding(webBinding); var messageEncodingElement = binding.Elements.Find<WebMessageEncodingBindingElement>(); messageEncodingElement.ContentTypeMapper = new ArcGisWebContentTypeMapper(); // Create endpoint for the geocoder REST service. var contract = ContractDescription.GetContract(typeof(IGeocodingService)); var serviceAddress = new EndpointAddress(serviceInfo.RestUrl); var endpoint = new WebHttpEndpoint(contract, serviceAddress); endpoint.Binding = binding; // Replace default endpoint behavior with a customized one. endpoint.Behaviors.Remove<WebHttpBehavior>(); endpoint.Behaviors.Add(new GeocodingServiceWebHttpBehavior()); // Create the geocoder instance. var channelFactory = new WebChannelFactory<IGeocodingService>(endpoint); var client = new GeocodingServiceClient(channelFactory, serviceInfo, exceptionHandler); return new WorldGeocoder(serviceInfo, client); }
/// <summary> /// Initializes a new instance of the <see cref="GeocodingServiceClient"/> class. /// </summary> /// <param name="channelFactory">The reference to the channel factory instance /// to be used for creating communication channels for the geocoder service.</param> /// <param name="serviceInfo">The configuration information for the geocoder /// service.</param> /// <param name="exceptionHandler">Exception handler.</param> /// <exception cref="ArgumentNullException"><paramref name="channelFactory"/> or /// <paramref name="serviceInfo"/> is a null reference.</exception> public GeocodingServiceClient( ChannelFactory<IGeocodingService> channelFactory, GeocodingServiceInfo serviceInfo, IServiceExceptionHandler exceptionHandler) { CodeContract.RequiresNotNull("channelFactory", channelFactory); CodeContract.RequiresNotNull("serviceInfo", serviceInfo); CodeContract.RequiresNotNull("exceptionHandler", exceptionHandler); _serviceClient = new RestServiceClient<IGeocodingService>( channelFactory, serviceInfo.Title, exceptionHandler); }
/// <summary> /// Constructor. /// </summary> /// <param name="geocodingServiceInfo">Geocoding service info.</param> /// <param name="geocodeServer">Geocode server.</param> /// <param name="exceptionHandler">Exception handler.</param> internal Geocoder(GeocodingServiceInfo geocodingServiceInfo, AgsServer geocodeServer, IServiceExceptionHandler exceptionHandler) { Debug.Assert(exceptionHandler != null); _exceptionHandler = exceptionHandler; // Init geocoding properties. _propMods = new PropertySet(); _propMods.PropertyArray = new PropertySetProperty[2]; _propMods.PropertyArray[0] = _CreateProp("WritePercentAlongField", "TRUE"); _propMods.PropertyArray[1] = _CreateProp("MatchIfScoresTie", "TRUE"); _geocodingServiceInfo = geocodingServiceInfo; if (_geocodingServiceInfo == null) { throw new SettingsException(Properties.Resources.DefaultGeocodingInfoIsNotSet); } _geocodingServer = geocodeServer; // Create address fields. _CreateAddressFields(); _actualGeocodingInfo = new GeocodingInfo(geocodingServiceInfo); _locatorsInfos = new ReadOnlyCollection<LocatorInfo>( _actualGeocodingInfo.Locators ?? new LocatorInfo[] { }); foreach (var locator in _locatorsInfos) { if (!_locators.ContainsKey(locator.Name)) { _locators.Add(locator.Name, locator); } } var fields = _geocodingServiceInfo.FieldMappings.FieldMapping.Select(mapping => (AddressPart)Enum.Parse( typeof(AddressPart), mapping.AddressField, true)); _defaultLocator = new LocatorInfo( string.Empty, string.Empty, true, true, SublocatorType.Streets, fields); // Geocoder should be initialized later. _inited = false; }
/// <summary> /// Initializes a new instance of the <see cref="WorldGeocoder"/> class. /// </summary> /// <param name="serviceInfo">The geocoding service configuration information.</param> /// <param name="client">The geocoding service client object.</param> /// <exception cref="System.ArgumentNullException"><paramref name="serviceInfo"/> or /// <paramref name="client"/> is a null reference.</exception> public WorldGeocoder( GeocodingServiceInfo serviceInfo, IGeocodingServiceClient client) { CodeContract.RequiresNotNull("serviceInfo", serviceInfo); CodeContract.RequiresNotNull("client", client); _serviceInfo = serviceInfo; _client = client; _client.ReverseGeocodeCompleted += _ClientReverseGeocodeCompleted; _locatorsInfos = new ReadOnlyCollection<LocatorInfo>(new List<LocatorInfo>()); }
/// <summary> /// Constructor. /// </summary> /// <param name="geocodingServiceInfo">Geocoding info from data layer.</param> internal GeocodingInfo(GeocodingServiceInfo geocodingServiceInfo) { Debug.Assert(geocodingServiceInfo != null); // Copy internal locators info. if (geocodingServiceInfo.InternalLocators != null) { _locators = new List<LocatorInfo>(); foreach (SublocatorInfo sublocator in geocodingServiceInfo.InternalLocators.SublocatorInfo) { LocatorInfo LocatorInfo = LocatorInfo.CreateLocatorInfo(sublocator); _locators.Add(LocatorInfo); } } }