Climate App DotNet XML Web Services
Climate App DotNet XML Web Services
1
// add ahmedabed
al.Add(19.4);
al.Add(67);
db.Add("Ahmedabad", al);
al.Clear();
// add madurai city
al.Add(22.54);
al.Add(73);
db.Add("Madurai", al);
al.Clear();
// add delhi city
al.Add(11.85);
al.Add(53);
db.Add("Delhi", al);
al.Clear();
// add mumbai city
al.Add(23.68);
al.Add(75);
db.Add("Mumbai", al);
al.Clear();
// add mysore city
al.Add(20.37);
al.Add(69);
db.Add("Mysore",al);
al.Clear();
// add kolkata city
al.Add(22.31);
al.Add(72);
db.Add("Kolkata", al);
2
al.Clear();
// add coimbatore city
al.Add(20.76);
al.Add(69);
db.Add("Coimbatore", al);
al.Clear();
// add lucknow city
al.Add(13.51);
al.Add(56);
db.Add("Lucknow", al);
}
[WebMethod]
public string DisplayWhetherReport_forCity(string cname)
{
// add city details using pre() method
pre();
bool flag = false;
double deg = 0, far = 0;
// fetch records one by one in dictionary using foreach loop
foreach (KeyValuePair<string, ArrayList> ele in db)
{
// check the given city with dictionary using = operator or Equals()
method
if (cname == ele.Key)
{
flag = true;
deg = double.Parse(ele.Value[0].ToString());
far = double.Parse(ele.Value[1].ToString());
break;
3
}
}
if (flag)
return cname + " City : " + deg.ToString() + " °C"+" /
"+far.ToString()+ " °F";
else
return "No city found...";
}
}
}
4
2. OUTPUT
2.1 WEB SERVICE CREATION – HOME PAGE
5
2.2 WEB SERVICE CREATION – INPUT SUBMISSION
6
2.3 WEB SERVICE CREATION – DISPLAYING RESULT
7
(B) CONSUMPTION – CLIENT SIDE DEVELOPMENT
Using Web Services in C# Client Application – ASP.NET Web Application
Client Application can be: Console App / Windows GUI / ASP.NET Web
8
Step 2 – Select “Add Service Reference”
9
Step 3 – Select “Advanced” button like below
10
Step 4 – Select Add Web Reference Button
11
Step 5 – Select Option 1 or Submit WebService URL in the URL Box – Here Option 1
is Selected (Clickable Hyperlink)
12
Step 6 – Detection of Current Developed Web Service – Climate App – Click
ClimateApp
13
Step 7 – Set Web Reference Name – User Defined Name and Click Add Reference
Button
14
Step 8 – Verification of Newly added Web Reference in Current Visual Studio
project
15
(AccWebServices.aspx)
1. SOURCE CODE
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="AccWebServices.aspx.cs"
Inherits="ClimateAppServices.AccWebServices" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Consuming Web Service</title>
<script lanuage="C#" runat="server">
public void disp(object sender, EventArgs e)
{
// get city name from text box
string cityname = tb.Text;
// create an object for local web reference
ClimateAppServices.localhostref.ClimateWhetherApp obj = new
ClimateAppServices.localhostref.ClimateWhetherApp();
string res=obj.DisplayWhetherReport_forCity(cityname);
// display the result in ASP.NET Label
rs.Text = res;
}
</script>
</head>
<body>
<center>
<form runat="server" >
<h2 style="color:forestgreen">Accessing Web Services via ASP.NET
Client Application</h2>
Enter the City Name:<br />
16
<asp:TextBox runat="server" ID="tb" Font-Bold="True" Width="214px"
BorderColor="#006600" Height="25px" />
<br />
<br />
<asp:Button runat="server" Text="Submit" BackColor="Red" Font-
Bold="True" ForeColor="White" Width="120px" BorderStyle="Solid"
OnClick="disp" BorderColor="#003366" Height="30px" />
<br />
<br />
<asp:Label runat="server" ID="rs" Font-Bold="True" Font-Size="X-
Large" ForeColor="#6600CC" />
</form>
</center>
</body>
</html>
2. OUTPUT
2.1 SUCCESS CASE 1 – CHENNAI CITY
17
2.2 SUCCESS CASE 2 – MADURAI CITY
18