/// <summary> /// Gets the country of the requesting user /// </summary> /// <returns>A string containing the country code (e.g. PK)</returns> public string GetCountry() { var cip = HttpContext.Current.Request.UserHostAddress; var requestMessageProperties = OperationContext.Current.IncomingMessageProperties; var remoteEndpointMessageProperty = requestMessageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty; if (remoteEndpointMessageProperty != null) { LogManager.CurrentInstance.InfoLogger.LogInfo(System.Reflection.MethodBase.GetCurrentMethod().GetType(), "Ip address:" + remoteEndpointMessageProperty.Address); try { return(GeoLocator.GetLocation(remoteEndpointMessageProperty.Address)); } catch (ApplicationException appExp) { NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)(Convert.ToInt32(appExp.Message))); return(null); } } else { LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().GetType(), "Endpoint message property is null."); NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.ServerInternalError); return(null); } }
public async Task GeoCoding_Shall_Work_With_Valid_Address() { var config = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .Build(); var address = $"Rua das Palmeiras, 127, Gopouva, Guarulhos, São Paulo, Brasil"; var location = await locator.GetLocation(config, address); Assert.IsNotNull(location); }