web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Calling weather web api in C# console app

(0) ShareShare
ReportReport
Posted on by 195

Hi friends,

Please find the below code for Calling weather web api in C# console app.

Nuget Package:  Newtonsoft.Json;

Thanks,

Bharath

If it is useful Hit"Like".

======================================================

using Newtonsoft.Json.Linq;
using System;
using System.Net;
namespace Calling_External_API
{
class Program
{
static void Main(string[] args)
{
string results = "";

string city;
Console.Write("Enter a city- ");
city = Console.ReadLine();

using (WebClient wc = new WebClient())
{

string searchtext = "select item.condition from weather.forecast where woeid in (select woeid from geo.places(1) where text='" + city + "') and u='c'";
results = wc.DownloadString("https://query.yahooapis.com/v1/public/yql?q=" + searchtext + "&format=json");

dynamic jo = JObject.Parse(results);
var items = jo.query.results.channel.item.condition;
var code = items.code;
var temp = items.temp;
var text = items.text;
var date= items.date;

Console.WriteLine("\n Temperature in "+city +" is " + temp + "°C");
Console.WriteLine("\n Today" + " - " + text);
Console.Read();
}
}

}

=====================================================

output:

weather.PNG

*This post is locked for comments

I have the same question (0)
  • Arun Vinoth Profile Picture
    11,615 Moderator on at

    Thanks for the very informative post.

    This would be really organized when you start writing a blog post: community.dynamics.com/.../136.request-a-new-blog-or-blog-to-syndicate

    Here, we will post our questions/problems to get answers/solutions from fellow community members.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans