How to Create a Simple Web Service and Use it in ASP.Net

Slides:



Advertisements
Similar presentations
Slickr : A Capstone Web Development Project Using Databases, ASP.NET, Web Services, and AJAX Mark Frydenberg Computer Information Systems Dept. Bentley.
Advertisements

1 Web Services I: Returning Data in XML Format. 2 Service-Oriented Architecture (SOA) Old Model for Applications Executables running on individual computers.
Introduction to Web Application Development with.Net and Web Service ISYS 350.
XML Web Services ASP.NET. Overview of Web Services (Page 1) Web Service – Part or all of a Web application that is publicly exposed so that other applications.
Creating web service (and client application) with Visual Studio 2008 Create web service project New project->web->ASP.NET web service application (with.
1 Web Services Visual C# 2008 Step by Step Chapter 30.
Web Service Project (.NET) Dr. Dante Ciolfi (chawl fee)
11 ASP.NET Controls Beginning ASP.NET 4.0 in C# 2010 Chapter 6.
ASP.Net, Web Forms and Web Controls 1 Outline Introduction Simple HTTP Transaction System Architecture Creating and Running a Simple Web Form Example Web.
Introduction to.Net and ASP.Net Course Introduction Build Your Own ASP.Net Website: Chapter 1 Microsoft ASP.Net Walkthrough: Creating a Basic Web Forms.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
JavaScript & jQuery the missing manual Chapter 11
DR.JOHN ABRAHAM PROFESSOR UTPA ASP.NET. ACTIVE SERVER PAGES (ASP) Web application development environment Web applications use web browser to display.
HTML, GUI, ASP.NET Rina Zviel-Girshin Lecture 2
Beginning Web Site Development Module 1 – Dynamic Web Site Development Fundamentals of building dynamic Web sites with ASP.NET 2.0 and C# Version.
Christopher M. Pascucci.NET Programming: Forms & Controls.
INSPIRING CREATIVE AND INNOVATIVE MINDS Module 4: Adding Code to a Microsoft ASP.NET Web Form Implementing Code-Behind Pages Adding Event Procedures to.
ASP.NET Web Application and Development Digital Media Department Unit Credit Value : 4 Essential Learning time : 120 hours Digital.
Creating Custom Controls with User Controls. Including Standard Content with User Controls Global Super Company Global Super Company We mean business!
Session 08: Architecture Controllers or Managers Graphical User Interface (GUI) FEN AK - IT Softwarekonstruktion.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
1 Data Bound Controls II Chapter Objectives You will be able to Use a Data Source control to get data from a SQL database and make it available.
Internet Technologies and Web Application Web Services With ASP.NET Tutorial: Introduction to.
.NET Fundamentals ASP.NET Web Services December 11, 2003.
1.NET Web Forms Web Services © 2002 by Jerry Post.
Introduction to ASP.NET T.Ahlam Algharasi. The Visual Studio IDE Start page 2.
© Chinese University, CSE Dept. Distributed Systems / Simple Example Open Microsoft Visual Studio 2005:
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Unit 2 : Creating a Microsoft ASP.NET Web Form.
Global.asax file. Agenda What is Global.asax file How to add the Global.asax file What are the default events available Explanation to Application_Level.
Dynamic Dropdown Lists 1. Objectives You will be able to Use Dropdown Lists to solicit multiple choice user input in an ASPX web page. Populate a Dropdown.
XML Web Service. Overview of XML Web Service ASP.NET XML Web services enable you to remotely access the properties and methods of classes across a network.
Session 4: HTML and Web Server Controls. Outline Creating Web Forms Using Server Controls HTML Server Controls Web Server Controls Writing ASP Code Inline.
Introduction to Web Services. Examples Using a Web Service Creating a new Web Service.
1 CS 3870/CS 5870: Note 20 Web Service. 2 What is Web Service? Providing functionality online to other applications, Web and Windows applications. The.
Week Six : Writing Web Services Aims: Creating and Consuming student’s first Web Services Learning Outcomes: Familiarity with VS.NET for creating and consuming.
Module 9: Using XML Web Services in a C# Application.
Chapter 7: Creating and Consuming XML Web Services Understanding XML Web Services Creating XML Web Services Deploying and Discovering XML Web Services.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Understanding Web Applications Lesson 4. Objective Domain Matrix Skills/ConceptsMTA Exam Objectives Understanding Web Page Development Understand Web.
Web Application Development Introduction. Lesson: Creating Web Forms What is a Web Form? Creating a Web Form with Visual Studio.NET.
Lesson 15 Web Services. What Are Web Services Web services are programmable and reusable, much like component software, except that they are more easily.
1 CS 3870/CS 5870: Note 13 Web Service. 2 What is Web Service? Providing functionality online to other Web applications SOAP Simple Object Access Protocol.
11 ASP.NET Server Controls Beginning ASP.NET in C# and VB Chapter 4.
.NET Mobile Application Development XML Web Services.
1111 Creating ASPX Controls Programatically Objectives You will be able to Dynamically add controls to a page. Dynamically alter properties of controls.
11 User Controls Beginning ASP.NET in C# and VB Chapter 8.
Creating a Web Site Creating a new Web site Defining and using folders Creating and editing Web pages Viewing pages in a Web browser.
11 jQuery Web Service Client. 22 Objectives You will be able to Use JSON (JavaScript Object Notation) for communcations between browser and server methods.
ASP.NET Part 2 Instructor: Charles Moen CSCI/CINF 4230.
Visual Studio ITEC 420.
Validation & Rich Controls
Computing with C# and the .NET Framework
ASP.NET AJAX.
ASP.NET Forms.
CS 3870/CS 5870 Web Service.
Allowing File Uploads.
Security Basics and ASP.NET Support
Introduction to Client-Server Programming
CS 3870/CS 5870 AJAX Prog8.
برمجه صفحات الانترنتASP
Web Services Introduction
Consuming Webservice in AX 2012
Introducing ASP.net with Visual Studio Environment
Multifarious Systems 1 Visual studio 2008 & ASP.NET.
Static and Dynamic Web Pages
ASP.NET.
E-commerce Applications Development
ASP.NET 2.0 Overview Created By: Ajay Bahoriya.
Validation & Rich Controls
Allowing File Uploads.
Presentation transcript:

How to Create a Simple Web Service and Use it in ASP.Net

How to Create a Simple Web Service and Use it in ASP.Net What is Web Service? A Web Service is a reusable piece of code used to communicate among Heterogeneous Applications. Once a web service is created and hosted on the server in the internet it can be consumed by any kind of application developed in any technology.

How to Create a Simple Web Service and Use it in ASP.Net How to create a Web Service Step 1 Go to Visual Studio then click on "File" -> "Website" -> "ASP.NET empty website template". Then provide the website name (for example: WebServiceSample).

Step 2 Add a Web Service File Go to Solution Explorer, then select the solution then click on "Add new item". Choose the Web Service template. Enter the name (for example: Airthmatic.cs) then click on "Add".

This will create the following two files: Airthmatic.asmx (the service file) Airthmatic.cs (the code file for the service; it will be in the "App_code" folder)

Open the file Airthmatic.cs and write the following code using System;    using System.Collections.Generic;    using System.Linq;    using System.Web;    using System.Web.Services;    /// <summary>    /// used for Airthmatic calculation    /// </summary>    [WebService(Namespace = "http://tempuri.org/")]    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.    // [System.Web.Script.Services.ScriptService]    public class Airthmatic : System.Web.Services.WebService    {        public Airthmatic()   {            //Uncomment the following line if using designed components            //InitializeComponent();        }        [WebMethod]        public int Add(int x, int y)        {            return x + y;        }    

  [WebMethod]        public int Sub(int x, int y)        {            return x - y;        }        [WebMethod]        public int Mul(int x, int y)            return x * y;        public int Div(int x, int y)            return x / y;    }  

Attaching the WebMethod attribute to a Public method indicates that you want the method exposed as part of the XML Web service. You can also use the properties of this attribute to further configure the behavior of the XML Web service method. The WebMethod attribute provides the following properties BufferResponse CacheDuration Description EnableSession MessageName TransactionOption For more details of web methods click here. Step 3 To see whether the service is running correctly go to the Solution Explorer then open "Airthmatic.asmx" and run your application. Now you will find all the method names in the browser.

To see the WSDL format click on the service description link or add " To see the WSDL format click on the service description link or add "?WSDL" to the URL. Example http://localhost:65312/WebServiceSample/Airthmatic.asmx?WSDL It will show the WSDL.

To determine whether the functions are working, click on one of the functions (for example: "Add"). Now you will see two TextBoxes for checking. Enter the value for x and y and click on the "Invoke" button. Now you will see the result in an open standard form (XML).

Now your service is ready for use Now your service is ready for use. Step 4 Creating the client application Now create a website and design your form as in the following screen

<body>        <form id="form1" runat="server">        <div>            <table border="2" cellpadding="2" cellspacing="2">                <tr>                    <td align="right">                        <asp:Label ID="Label1" runat="server"  Text="Enter 1st Number"></asp:Label>                    </td>                    <td align="left">                        <asp:TextBox ID="txtFno" runat="server"></asp:TextBox>                </tr>                        <asp:Label ID="Label2" runat="server" Text="Enter 2nd Number"></asp:Label>                        <asp:TextBox ID="txtSno" runat="server"></asp:TextBox>  

 <tr>                    <td align="right">                        <asp:Label ID="Label3" runat="server" Text="Result"></asp:Label>                    </td>                    <td align="left">                        <asp:Label ID="lblResult" runat="server"></asp:Label>                </tr>                <tr>                    <td align="center">            <asp:Button ID="btnAdd" runat="server" Text="Add(+)" OnClick="btnAdd_Click" />         <asp:Button ID="btnSub" runat="server" Text="Sub(-)" OnClick="btnSub_Click" />            <asp:Button ID="BtnMul" runat="server" Text="Mul(*)" OnClick="BtnMul_Click" />        <asp:Button ID="btnDiv" runat="server" Text="Div(/)" OnClick="btnDiv_Click" />            </table>        </div>        </form>    </body>  

Step 5 Add a web reference to the Website   Go to Solution Explorer then select the solution then click on "AddWeb Reference" then within the URL type the service reference path. (For example: http://localhost:65312/WebServiceSample/Airthmatic.asmx) then click on the "Go" button. Now you will see your service methods. Change the web reference name from "localhost" to any other name as you like (for example: WebAirthmatic). Click on the "Add Reference" button. It will create a Proxy at the client side.

Now go to the cs code and add a reference for the Service Now go to the cs code and add a reference for the Service. Example using WebAirthmatic; Write the following code.

using System;   using System.Collections.Generic;   using System.Linq;   using System.Web;   using System.Web.UI;   using System.Web.UI.WebControls;   using WebAirthmatic;   public partial class _Default : System.Web.UI.Page   {       Airthmatic obj = new Airthmatic();       int a, b, c;       protected void Page_Load(object sender, EventArgs e)       {       }       protected void btnAdd_Click(object sender, EventArgs e)           a = Convert.ToInt32(txtFno.Text);           b = Convert.ToInt32(txtSno.Text);           c = obj.Add(a, b);           lblResult.Text = c.ToString();  

protected void btnSub_Click(object sender, EventArgs e)       {           a = Convert.ToInt32(txtFno.Text);           b = Convert.ToInt32(txtSno.Text);           c = obj.Sub(a, b);           lblResult.Text = c.ToString();       }       protected void BtnMul_Click(object sender, EventArgs e)           c = obj.Mul(a, b);       protected void btnDiv_Click(object sender, EventArgs e)           c = obj.Div(a, b);   }  

Now first run the Web service then the application. Now you will be able to communicate with the web service.