Get the Weather Forcast for Next 7 days using Web Service
Here is the Code to get the weather forcat for coming 7 days in US with reference to Zip or Place
we use a Web Reference for this and in a grid we display the weather forcasts
create a website in asp.net c#
add a page Getweatherdetails.aspx
now right click on solution explorer and add web reference
add this url
http://www.webservicex.net/WeatherForecast.asmx?WSDL
now click add reference
//in Getweatherdetails.aspx page
<asp:Label ID="Label1" runat="server" Text="Enter Zip Code"></asp:Label>
<asp:TextBox ID="tbzip" runat="server"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Text="Enter place Name"></asp:Label>
<asp:TextBox ID="tbplc" runat="server"></asp:TextBox>
<asp:Button ID="btnget" runat="server" Text="Get Forcats" OnClick="btnget_Click" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Get Forcats" /
<asp:GridView ID="gdweather" runat="server" CellPadding="4" Font-Names="Arial" Font-Size="8pt" ForeColor="#333333" GridLines="None" Height="1px" Width="594px" >
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
// in Getweatherdetails.aspx.cs
get namespase
using net.webservicex.www;
protected void btnget_Click(object sender, EventArgs e)
{
net.webservicex.www.WeatherForecast wfc = new net.webservicex.www.WeatherForecast();
WeatherData[] wd;
wd = wfc.GetWeatherByZipCode(tbzip.Text).Details;
gdweather.DataSource = wd;
gdweather.DataBind();
for (int i = 0; i < gdweather.Rows.Count; i++)
{
Image img = new Image();
img.Height = 75;
img.ImageUrl=gdweather.Rows[i].Cells[5].Text;
gdweather.Rows[i].Cells[5].Controls.Add(img);
}
// Response.Write(gdweather.Columns.Count.ToString());
}
protected void Button1_Click(object sender, EventArgs e)
{
net.webservicex.www.WeatherForecast wfc = new net.webservicex.www.WeatherForecast();
WeatherData[] wd;
wd = wfc.GetWeatherByPlaceName (tbplc.Text).Details;
gdweather.DataSource = wd;
gdweather.DataBind();
for (int i = 0; i < gdweather.Rows.Count; i++)
{
Image img = new Image();
img.Height = 75;
img.ImageUrl = gdweather.Rows[i].Cells[5].Text;
gdweather.Rows[i].Cells[5].Controls.Add(img);
}
}
