- gpsrunnermaps.zip
- Web
- AzureSamples
- AspProviders
- GoogleMapControl
- GpsRunnerMaps
- Administrator.txt
- GpsRunnerMaps.gpState
- GpsRunnerMaps.sln
- GpsRunnerMaps
- GpsRunnerMaps
- AjaxControlToolkit.dll
- AjaxControlToolkit.pdb
- bin
- Debug
- GpsRunnerMaps.csx
- roles
- GpsRunnerMaps_WebRole
- approot
- App_GlobalResources
- App_Themes
- Black
- Images
- AppCode
- bin
- icons
- base
- x86
- diagnostics
- x86
- GpsRunnerMaps.ccproj
- GpsRunnerMaps.ccproj.user
- obj
- Debug
- ServiceConfiguration.cscfg
- ServiceDefinition.csdef
- GpsRunnerMaps_WebRole
- TrainingCenterDatabasev2.xsd
- IpToCountry
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.IO;
using System.Globalization;
using System.Web.Script.Services;
using System.Web.Services;
namespace PS.GpsRunnerMaps
{
// To allow this Web Service to be called from script using ASP.NET AJAX,
// we need to set the following attribute.
[ScriptService]
[WebService(Namespace = "Panoramio")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class PanoramioService : WebService
{
[WebMethod]
public string GetWeatherByLocation(double lat, double lng)
{
return Panoramio.GetWeatherByLocation(lat, lng);
}
} // end class
public class Panoramio
{
private readonly static string FindNearbyWeatherUrl =
"http://ws.geonames.org/findNearByWeatherJSON?lat={0}&lng={1}";
public static string GetWeatherByLocation(double lat, double lng)
{
string formattedUri = String.Format(CultureInfo.InvariantCulture,
FindNearbyWeatherUrl, lat, lng);
HttpWebRequest webRequest = GetWebRequest(formattedUri);
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
string jsonResponse = string.Empty;
using (StreamReader sr = new StreamReader(response.GetResponseStream()))
{
jsonResponse = sr.ReadToEnd();
}
return jsonResponse;
}
private static HttpWebRequest GetWebRequest(string formattedUri)
{
// Create the request’s URI.
Uri serviceUri = new Uri(formattedUri, UriKind.Absolute);
// Return the HttpWebRequest.
return (HttpWebRequest)System.Net.WebRequest.Create(serviceUri);
}
} // end class
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Software developer and Microsoft Trainer, Athens, Greece (MCT, MCSD.net, MCSE 2003, MCDBA 2000,MCTS, MCITP, MCIPD).