0% found this document useful (0 votes)
32 views18 pages

Climate App DotNet XML Web Services

Uploaded by

Vignesh Senthil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views18 pages

Climate App DotNet XML Web Services

Uploaded by

Vignesh Senthil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

II. WRITE AN ASP.

NET WEB SERVICES APPLICATION TO CREATE CLIMATE


WHETHER APP
• Creation
• Consumption
(A) CREATION – SERVER SIDE IMPLEMENTATION
(ClimateApp.asmx)
1. SOURCE CODE
using System.Collections;
using System.Collections.Generic;
using System.Web.Services;
using System;
namespace ClimateAppServices
{
/// <summary>
/// Summary description for WebService1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
public class ClimateWhetherApp : System.Web.Services.WebService
{
Dictionary<string, ArrayList> db = new Dictionary<string, ArrayList>();
ArrayList al = new ArrayList();

public void pre()


{
// add chennai city
al.Add(23.13);
al.Add(74);
db.Add("Chennai", al);
al.Clear();

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

Application Type : ASP.NET Web Application


Language : C#.NET
Development of Web Services : Client Side via HTTP Get
Local Reference : localhost
IDE : Visual Studio
OS : Windows 10

STEP 1 - Right Click on References

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

2.3 FAILURE CASE 1 – LONDON CITY

18

You might also like