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.

Slides:



Advertisements
Similar presentations
Intesar G Ali IT DepartmentPalestinian Land Authority Web services Prepared by: Intesar Ali IT Department PLA August 2010.
Advertisements

Introduction to MVC Adding a View Page NTPCUG Tom Perkins, Ph.D.
11 Getting Started with ASP.NET Beginning ASP.NET 4.0 in C# 2010 Chapters 5 and 6.
Windows Communication Foundation and Web Services.
Web Development in Microsoft Visual Studio Slide 2 Lecture Overview Introduce Visual Studio 2013 Create a first ASP.NET application.
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.
Chapter 12 Extending Web Applications. ASP.NET 2.0, Third Edition2.
Creating web service (and client application) with Visual Studio 2008 Create web service project New project->web->ASP.NET web service application (with.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
1 Web Services Visual C# 2008 Step by Step Chapter 30.
Web Services February 14 th, Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II.
Tutorial -01. Objective In this session we will discuss about : 1.What is MVC? 2.Why MVC? 3.Advantages of MVC over ASP.NET 4.ASP.NET development models.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
ASP.Net, Web Forms and Web Controls 1 Outline Introduction Simple HTTP Transaction System Architecture Creating and Running a Simple Web Form Example Web.
Chapter 9 Web Applications Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
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.
9-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
JavaScript & jQuery the missing manual Chapter 11
ASP.NET The.NET Framework. The.NET Framework is Microsoft’s distributed run-time environment for creating, deploying, and using applications over the.
11 Getting Started with C# Chapter Objectives You will be able to: 1. Say in general terms how C# differs from C. 2. Create, compile, and run a.
Microsoft Visual Basic 2005: Reloaded Second Edition
C Copyright © 2009, Oracle. All rights reserved. Appendix C: Service-Oriented Architectures.
CIS 375—Web App Dev II Microsoft’s.NET. 2 Introduction to.NET Steve Ballmer (January 2000): Steve Ballmer "Delivering an Internet-based platform of Next.
Creating Web Applications Using ASP.NET Chapter Microsoft Visual Basic.NET: Reloaded 1.
Web Programming: Client/Server Applications Server sends the web pages to the client. –built into Visual Studio for development purposes Client displays.
© Minder Chen, ASP.NET 2.0: Introduction - 1 ASP.NET 2.0 Minder Chen, Ph.D. Framework Base Class Library ADO.NET: Data & XML.
Tutorial 121 Creating a New Web Forms Page You will find that creating Web Forms is similar to creating traditional Windows applications in Visual Basic.
CSCI 6962: Server-side Design and Programming Web Services.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
CS 390- Unix Programming Environment CS 390 Unix Programming Environment Topics to be covered: Distributed Computing Fundamentals.
1 Working with Menus and Dialog Boxes. 2 Objectives You will be able to Create and edit menus for Windows Forms applications. Write code to handle menu.
Lecture 15 Introduction to Web Services Web Service Applications.
ASP.NET.. ASP.NET Environment ASP.NET is Microsoft's programming framework that enables the development of Web applications and services. It is an easy.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Programming with Visual Web Developer Chapter 9.
Internet Technologies and Web Application Web Services With ASP.NET Tutorial: Introduction to.
Murach’s ASP.NET 4.0/VB, C1© 2006, Mike Murach & Associates, Inc.Slide 1.
C# Tutorial -1 ASP.NET Web Application with Visual Studio 2005.
.Net and Web Services Security CS795. Web Services A web application Does not have a user interface (as a traditional web application); instead, it exposes.
© Chinese University, CSE Dept. Distributed Systems / Simple Example Open Microsoft Visual Studio 2005:
Microsoft Visual Basic 2008 CHAPTER TWELVE Cell Phone Applications and Web Services.
Web Services. ASP.NET Web Services  Goals of ASP.NET Web services:  To enable cross-platform, cross- business computing  Great for “service” based.
Introducing ASP.NET 2.0. Internet Technologies WWW Architecture Web Server Client Server Request Response Network HTTP TCP/IP PC/Mac/Unix + Browser (IE,
Using Microsoft Visual Studio 2005 Original by Suma Rao Revised by John G. McMahon ( 9/6/2008 )
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.
Introduction to Web Services. Examples Using a Web Service Creating a new Web Service.
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.
Understanding Web Applications Lesson 4. Objective Domain Matrix Skills/ConceptsMTA Exam Objectives Understanding Web Page Development Understand Web.
Web Services from 10,000 feet Part I Tom Perkins NTPCUG CertSIG XML Web Services.
Intro to Web Services Dr. John P. Abraham UTPA. What are Web Services? Applications execute across multiple computers on a network.  The machine on which.
.NET Mobile Application Development XML Web Services.
11 Getting Started with ASP.NET Beginning ASP.NET in C# and VB Chapters 1 and 2.
1 Project 4 Address Lookup. Project 4 Write an ASP.NET app that permits users to retrieve addresses from a potentially large list of addresses. There.
11 User Controls Beginning ASP.NET in C# and VB Chapter 8.
Introduction to Web Services Srinath Vasireddy Support Professional Developer Support Microsoft Corporation.
11 jQuery Web Service Client. 22 Objectives You will be able to Use JSON (JavaScript Object Notation) for communcations between browser and server methods.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Chapter 1 Getting Started with ASP.NET Objectives Why ASP? To get familiar with our IDE (Integrated Development Environment ), Visual Studio. Understand.
Windows Communication Foundation and Web Services
Jim Fawcett CSE681 – SW Modeling & Analysis Spring 2005
Web Programming Developing Web Applications including Servlets, and Web Services using NetBeans 6.5 with GlassFish.V3.
Writing simple Java Web Services using Eclipse
Windows Communication Foundation and Web Services
CIS16 Application Development Programming with Visual Basic
Chapter 42 Web Services.
Distributed System using Web Services
SOAP web services in Microsoft Azure
Presentation transcript:

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 a client program for a simple web service.

33 What are Web Services? Make web apps available to programs Like they are available to human users via web browsers. Use HTTP SOAP XML Motivation: Platform independence Drawback High communication overhead

44 Web Service Frameworks Version 3.5 of the.NET Framework provides two quite different ways to develop web services: ASP.NET Web Services The traditional approach Windows Communications Foundation New in.NET 3.5 and Visual Studio 2008 Visual Studio 2010 supports both methods. We will follow the traditional approach.

55 What is a.NET Web Service? Web Services in the.NET environment A form of remote method invocation (RMI) Layered on top of basic message based web service protocol. SOAP Simple Object Access Protocol Motivation: Method invocation is familiar to programmers. No need to understand the SOAP protocol. No need to work directly with messages. This is the only form of web service that we will study.

66 How do RMI Web Services Work? Client code invokes “proxy” method on own system. Same interface as the remote method Proxy prepares a SOAP message encoding identification of function and arguments. Proxy sends message to web server on remote system. Web server on remote system parses the SOAP message and invokes the specified method. Web server sends result back as a SOAP message. Proxy on client system parses message and delivers result.

77 How do RMI Web Services Work? The interface seen by the client program is the same as if the method were local. But don't be deceived! There is a round trip message exchange before the remote function returns. MUCH slower than a local function. Good web services do a lot of work on a single method invocation.

88 How do web services work? When using ASP.NET and Visual Studio Library functions handle most of the work. It is not necessary to understand the SOAP protocol or message coding. Let’s try a simple example: Hello Service A service that returns the message “Hello, world!” whenever it is invoked.

99 Creating a Web Service In Visual Studio 2010, create a new web site using the Web Service template. Note: New web site, not new project. Location: File System Language: C# Template: ASP.NET Web Service

10 New Web Site

11 Creating a Web Service In the New Web Site box Select.NET Framework 3.5 NOT 4.0 Installed Templates: Visual C# ASP.NET Web Service Name: Hello_Service

12 Creating a Web Service

13 Creating a Web Service Visual Studio creates Web site with the name Hello_Service. The name specified for the web site Containing folders App_Code and App_Data Initial source code file called Service.asmx

14 The “Service” Will be visible on the Internet when deployed to a Microsoft web server. Processed by the Microsoft Web Server (IIS) like.aspx files.

15 Initial Code for Our Web Service A very simple example provided by Visual Studio.

16 Initial Code for Our Web Service Note the class name, “Service”. Also the name of the.asmx file Can be any name we wish. “Service” is just the default. Let’s change the class name to “Hello_Service”

17 Create New Web Site Change file names from Service to Hello_Service Hello_Service.asmx App_Code\Hello_Service.cs In Hello_Service.cs Change name of class from Service to Hello_Service Also constructor

18 Rename the.asmx File Update CodeBehind file name and Class name.

19 Set Port Number In Solution Explorer Select Project Main Menu > View > Properties Window

20 Set Port Number

21 Set Port Number

22 Set Port Number In the Properties Window Set Use dynamic ports to false. Set Port number to 4500 An arbitrary choice

23 Set Port Number

24 Class “Hello_Service" Examine class Hello_Service Derived from System.Web.Services.WebService Note attributes (in square brackets) Compiler directives Method HelloWorld has attribute [WebMethod] Any method to be provided to remote clients must have attribute [WebMethod]

25 Attributes of Class “Hello_Service" [WebServiceBinding(...) ] Identifies the level of web services interoperability that this web service will conform to. Leave at default setting

26 Attributes of Class "Service" [WebService( Namespace =...) ] specifies a namespace to uniquely identify the web service. Set your Namespace to your URL For example, in my case, This is just an easy way to define a name that will be unique over the entire Internet. There is no significance to the specific choice.

27 Hello_Service Class Definition

28 HelloWorld() Normally you would delete the HelloWorld() method and enter your own methods in its place. For this first example, we will leave it. Define a web method called HelloWorld() which will return the string “Hello World” to any client that invokes the service.

29 Build the Service Now build the service Main Menu > Build > Build Web Site

30 Testing the Service How do we test the service? It needs a client! Browsers provide a default client that we can use to test a service running on Visual Studio. Right click on Hello_Service.asmx in the Solution Explorer window. Select View in Browser.

31 Testing the Service

32 Testing the Service in Chrome Click here

33 Testing the Service in Chrome Click here

34 Here is the Result Click the first tab to return, then click the “Back” button.

35 Service Description Click here

36 Service Description - WSDL End of Section

37 WSDL Web Services Description Language A web service must be able to provide a detailed specification of its interface upon request. Permits the client to construct a SOAP message in the correct format for this service. Visual Studio handles this transparently when we use it to write client software. Click the browser's back button to return to the web service page and leave it running.

38 Consuming a Web Service Now let’s write a client app to use the HelloWorld web service. Leave this web service running. Clients can be either PC programs or web apps Including other web services. Since this is a web apps class, let's write a web app to use the Hello_Service.

39 Consuming a Web Service We will need a proxy Presents same appearance to the client program as the remote method Communicates with the web server using SOAP messages. Passes result to client program as if the method had been executed locally.

40 Consuming a Web Service Start up another instance of Visual Studio First instance must continue running to support the service. Create a new C# ASPX.NET Web Site Call it Test_Hello.

41 Creating a Client App

42 Creating a Client App

43 Creating a Client App Let the test app have a button to invoke the HelloService web method. A label to display the result.

44 Design the Form

45 Add Reference to the Web Service

46 Get URL of the Running Web Service Select and copy URL from address box

47 Paste in URL for the web service. (Or type it.) Then click. 47 Adding a Web Reference Browsing won’t work when the service is running in Visual Studio’s built in web server.

48 Adding a Web Reference

49 Adding a Web Reference Fill in a Web reference name. Than click “Add Reference”. The name is your choice, but should be meaningful.

50 Adding a Web Reference Visual Studio contacts the web site that we identified. Doesn't have to be on the same computer as it is in this case. Could be anywhere. Visual Studio gets the WSDL Web Service Specification from the web service. Using the WSDL spec, Visual Studio creates the proxy and makes it a part of our website.

51 Check the Solution Explorer

52 Recall the Service Definition The class that provides the HelloWorld remote method is called “Hello_Service”. HelloWorld is a method of class “Hello_Service”.

53 Using the Web Service We have to instantiate the Hello_Service class. Then invoke its HelloWorld method.

54 Open Code Window in Test Program

55 Include the Web Reference Name in "Usings" At the top, add using Hello_Service_on_localhost; The web reference that we added to the application This is the namespace in which the proxy class exists.

56 Default.aspx.cs with new “using”

57 Add an Event Handler Back in Design window Double click on the "Invoke HelloWorld" button, to generate an event handler for it. Fill in code as shown on the next slide

58 Event Handler private void btnInvokeHello_Click(object sender, EventArgs e) { Hello_Service hs = new Hello_Service(); try { lblResult.Text = hs.HelloWorld(); } catch (Exception ex) { lblResult.Text = ex.Message; } The proxy class generated when we added the web reference The specific method to invoke within the web service.

59 Try it! Build and run the test app.

60 Here is our result.

61 Summary: Creating a Web Service Client Know the URL and Interface definition for the web service. Create a normal web application (or PC application). Add a web reference. Specify URL of the web service. This adds a proxy class to the project. Proxy class interface is identical to that of the web service. Add “using” statement for the web reference. Instantiate the web service class. Invoke methods of the web service as if it were a local class. End of Presentation