 2006 Pearson Education, Inc. All rights reserved. 1 22 Web Services.

Slides:



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

Web Service Ahmed Gamal Ahmed Nile University Bioinformatics Group
Web Services Darshan R. Kapadia Gregor von Laszewski 1http://grid.rit.edu.
Web Services Nasrullah. Motivation about web service There are number of programms over the internet that need to communicate with other programms over.
CSE 1302 Lecture 8 Inheritance Richard Gesick Figures from Deitel, “Visual C#”, Pearson.
1 Chapter 12 Working With Access 2000 on the Internet.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 42 Web Services.
 2007 Pearson Education, Inc. All rights reserved JAX-WS Web Services, Web 2.0 and Mash-Ups.
Introduction to ASP.NET, Second Edition2 Chapter Objectives.
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.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
ASP.NET Programming with C# and SQL Server First Edition
Chapter 12 Extending Web Applications. ASP.NET 2.0, Third Edition2.
INTRODUCTION TO WEB SERVICES CS 795. What is a Web Service ? Web service is a means by which computers talk to each other over the web using HTTP and.
1 Web Services Visual C# 2008 Step by Step Chapter 30.
COMPUTER TERMS PART 1. COOKIE A cookie is a small amount of data generated by a website and saved by your web browser. Its purpose is to remember information.
Processing of structured documents Spring 2003, Part 6 Helena Ahonen-Myka.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
INTRODUCTION TO WEB DATABASE PROGRAMMING
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
© 2004 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill/Irwin Programming the Web Using ASP.Net Chapter 2: The ASP.Net Template Dave.
C Copyright © 2009, Oracle. All rights reserved. Appendix C: Service-Oriented Architectures.
IT533 Lectures Session Management in ASP.NET. Session Tracking 2 Personalization Personalization makes it possible for e-businesses to communicate effectively.
Web Services Dr. Awad Khalil Computer Science & Engineering Department AUC.
1 HRS2422 Web Services JAX-WS and SOAP Introduction  Web service – A software component stored on one computer that can be accessed via method.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
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.
Chapter 8 Cookies And Security JavaScript, Third Edition.
Murach’s ASP.NET 4.0/VB, C1© 2006, Mike Murach & Associates, Inc.Slide 1.
.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.
XML Web Services Architecture Siddharth Ruchandani CS 6362 – SW Architecture & Design Summer /11/05.
Web Services. ASP.NET Web Services  Goals of ASP.NET Web services:  To enable cross-platform, cross- business computing  Great for “service” based.
Dr. Azeddine Chikh IS444: Modern tools for applications development.
Copyright © 2012 Pearson Education, Inc. Chapter 9 Classes and Multiform Projects.
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.
1 Web Services Web and Database Management System.
 2008 Pearson Education, Inc. All rights reserved PHP.
Chapter 4 Introduction to Classes, Objects, Methods and strings
1 Web Servers (Chapter 21 – Pages( ) Outline 21.1 Introduction 21.2 HTTP Request Types 21.3 System Architecture.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Bookstore Application: Middle Tier Introducing Code-Behind Files, Session State.
Kemal Baykal Rasim Ismayilov
ASP.NET Web Services.  A unit of managed code installed under IIS that can be remotely invoked using HTTP.
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.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Lecture 4 Mechanisms & Kernel for NOSs. Mechanisms for Network Operating Systems  Network operating systems provide three basic mechanisms that support.
Web Services An Introduction Copyright © Curt Hill.
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
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.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
.NET Mobile Application Development XML Web Services.
Introduction to Web Services Presented by Sarath Chandra Dorbala.
DEVELOPING WEB SERVICES WITH JAVA DESIGN WEB SERVICE ENDPOINT.
Introduction to Web Services Srinath Vasireddy Support Professional Developer Support Microsoft Corporation.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 9 Web Services: JAX-RPC,
Web Services (Chapter 23 in [1]). 2 Outline Introduction Introduction.NET Web Services Basics.NET Web Services Basics Simple Object Access Protocol (SOAP)
1 Chapter 1 INTRODUCTION TO WEB. 2 Objectives In this chapter, you will: Become familiar with the architecture of the World Wide Web Learn about communication.
Java Web Services Orca Knowledge Center – Web Service key concepts.
Jim Fawcett CSE681 – SW Modeling & Analysis Spring 2005
ASP.NET Forms.
28 Web Services.
Web Programming Developing Web Applications including Servlets, and Web Services using NetBeans 6.5 with GlassFish.V3.
WEB SERVICES.
INTRODUCTION TO WEB SERVICES CS 795. What is a Web Service ? Web service is a means by which computers talk to each other over the web using HTTP and.
Chapter 23 – ASP.NET Outline 23.1 Introduction NET Overview
Chapter 9 Web Services: JAX-RPC, WSDL, XML Schema, and SOAP
Chapter 42 Web Services.
Presentation transcript:

 2006 Pearson Education, Inc. All rights reserved Web Services

 2006 Pearson Education, Inc. All rights reserved. 2 A client is to me a mere unit, a factor in a problem. — Sir Arthur Conan Doyle...if the simplest things of nature have a message that you understand, rejoice, for your soul is alive. — Eleonora Duse Protocol is everything. — Francoise Giuliani They also serve who only stand and wait. — John Milton

 2006 Pearson Education, Inc. All rights reserved. 3 OBJECTIVES In this chapter you will learn:  What a Web service is.  How to create Web services.  The important part that XML and the XML-based Simple Object Access Protocol play in enabling Web services.  The elements that comprise Web services, such as service descriptions and discovery files.  How to create a client that uses a Web service.  How to use Web services with Windows applications and Web applications.  How to use session tracking in Web services to maintain state information for the client.  How to pass user-defined types to a Web service.

 2006 Pearson Education, Inc. All rights reserved Introduction 22.2.NET Web Services Basics Creating a Web Service in Visual Web Developer Discovering Web Services Determining a Web Service’s Functionality Testing a Web Service’s Methods Building a Client to Use a Web Service 22.3Simple Object Access Protocol (SOAP) 22.4Publishing and Consuming Web Services Defining the HugeInteger Web Service Building a Web Service in Visual Web Developer Deploying the HugeInteger Web Service

 2006 Pearson Education, Inc. All rights reserved Creating a Client to Consume the HugeInteger Web Service Consuming the HugeInteger Web Service 22.5Session Tracking in Web Services Creating a Blackjack Web Service Consuming the Blackjack Web Service 22.6Using Web Forms and Web Services Adding Data Components to a Web Service Creating a Web Form to Interact with the Airline Reservation Web Service 22.7User-Defined Types in Web Services 22.8 Wrap-Up 22.9Web Resources

 2006 Pearson Education, Inc. All rights reserved Introduction Web Services -A class that allows its methods to be called by methods on other machines via common data formats and protocol Ex: HTTP and XML -The over-the-network method calls are commonly implemented through the Simple Object Access Protocol (SOAP) An XML-based protocol describes how to mark up requests and responses so that they can be transferred via protocols -Applications represent and transmit data in a standardized XML-based format using SOAP -Visual Web Developer and the.NET Framework provide a simple, user-friendly way to create Web services

 2006 Pearson Education, Inc. All rights reserved NET Web Services Basics Basics -Remote machine The machine on which the Web service resides -A Web service is typically implemented as a class -A compiled version of the Web service class is not placed in the current application’s directory -Requests to and responses from Web services created with Visual Web Developer are typically transmitted via SOAP Any client capable of generating and processing SOAP messages can interact with a Web service -Regardless of the language in which the Web service is written -Web services and SOAP are platform and language independent

 2006 Pearson Education, Inc. All rights reserved. 8 Performance Tip 22.1 Web services are not the best solution for certain performance-intensive applications, because applications that invoke Web services experience network delays. Also, data transfers are typically larger because data is transmitted in text-based XML formats.

 2006 Pearson Education, Inc. All rights reserved Creating a Web Service in Visual Web Developer Creating Web Services -Create a project of type ASP.NET Web Service. Visual Web Developer then generates the following: -Files to contain the Web service code Implements the Web service -An ASMX file Provides access to the Web service -A DISCO file Potential clients use to discover the Web service -Methods in a Web service are invoked through a Remote Procedure Call (RPC) These methods are marked with the WebMethod attribute -Makes the method accessible to other classes through RPCs Known as exposing

 2006 Pearson Education, Inc. All rights reserved. 10 Fig | Web service components.

 2006 Pearson Education, Inc. All rights reserved Discovering Web Services Discovery of Web services (DISCO) -Microsoft-specific technology used to locate Web services on a server -Four types of DISCO files facilitate the discovery process: -.disco files XML markup that describes for clients the location of Web services Accessed via a Web service’s ASMX page Contains references only to files in the current Web service -.vsdisco files XML markup that describes the locations of Web services is generated dynamically, then returned to the client Does not store the markup generated in response to a request Contain only a small amount of data and provide up-to-date information about a server’s available Web services Generate more overhead than.disco files do -A search must be performed every time a.vsdisco file is accessed -.discomap files The resulting data that is returned from accessing a.disco file -.map files

 2006 Pearson Education, Inc. All rights reserved Determining a Web Service’s Functionality Web Service’s Functionality -Web services normally contain a service description An XML document that conforms to Web Service Description Language (WSDL) -An XML vocabulary that defines the methods a Web service -Specifies lower-level information that clients might need

 2006 Pearson Education, Inc. All rights reserved Determining a Web Service’s Functionality (Cont.) ASMX File -Generated by the Visual Web Developer when a Web service is constructed -Presents Web method descriptions and links to test pages Allow users to execute sample calls to these methods -Specifies the Web service’s : Implementation class Optional code-behind file -Where the Web service is defined The assemblies -Referenced by the Web service -Accessed when the Web server receives a request for the Web service Invokes the Web service implementation -For more technical information about the Web service, access the WSDL file ASP.NET generates WSDL information dynamically -Ensures that clients receive the most current information about the Web service

 2006 Pearson Education, Inc. All rights reserved. 14 Fig | ASMX file rendered in a Web browser. Link to the service description Links to the Web service’s methods

 2006 Pearson Education, Inc. All rights reserved Testing a Web Service’s Methods SOAP and HTTP POST -Two options for sending and receiving messages in Web services -Web service’s wire format or wire protocol The protocol that transmits request-and-response messages SOAP is the more commonly used wire format -SOAP messages can be sent using several transport protocols -HTTP POST must use HTTP -When you test a Web service via an ASMX page, the ASMX page uses HTTP POST to test the Web service methods

 2006 Pearson Education, Inc. All rights reserved. 16 Fig | Service description for our HugeInteger Web service.

 2006 Pearson Education, Inc. All rights reserved. 17 Fig | Invoking a Web method from a Web browser.

 2006 Pearson Education, Inc. All rights reserved. 18 Fig | Results of invoking a Web method from a Web browser.

 2006 Pearson Education, Inc. All rights reserved. 19 Error-Prevention Tip 22.1 Using the ASMX page of a Web service to test and debug methods can help you make the Web service more reliable and robust.

 2006 Pearson Education, Inc. All rights reserved Building a Client to Use a Web Service Client Using a Web Service -To consume a Web service, add a Web reference to the client Adds files that allow the client to access the Web service -Visual C# 2005 accesses the Web service’s WSDL information and copies it into a WSDL file that is stored in the client project’s Web References folder Visual C# 2005 provides an Update Web Reference option The WSDL information is used to create a proxy class -Handles all the “plumbing” required for Web method calls When the client application calls a Web method, it actually calls a method in the proxy class -This method has the same name and parameters as the Web method that is being called Formats the call to be sent as a request in a SOAP message -The Web service receives this request as a SOAP message Executes the method call and sends back the result as another SOAP message -The proxy class deserializes the SOAP message containing the response and returns the results of the Web method that was called

 2006 Pearson Education, Inc. All rights reserved. 21 Fig |.NET Web service client after a Web reference has been added.

 2006 Pearson Education, Inc. All rights reserved Simple Object Access Protocol (SOAP) SOAP -Each request and response is packaged in a SOAP message XML message contains information that is required to process the message -The wire format used to transmit requests and responses must support all types passed between the applications -The request and all relevant information are packaged in a SOAP message and sent to the server on which the Web service resides -The Web service processes the contents which specify the method that the client wishes to execute and any arguments the client is passing to that method Known as parsing a SOAP message -The proper method is then called with the specified arguments and the response is sent back to the client in another SOAP message -The client parses the response to retrieve the result of the method call

 2006 Pearson Education, Inc. All rights reserved. 23 Fig | Interaction between a Web service client and a Web service.

 2006 Pearson Education, Inc. All rights reserved. 24 Outline HugeInteger.asmx Placeholders

 2006 Pearson Education, Inc. All rights reserved Publishing and Consuming Web Services Terms -Publishing Creating a Web services -Consuming Using a Web services Visual C# 2005 and Visual Web Developer create proxy classes for you

 2006 Pearson Education, Inc. All rights reserved Defining the HugeInteger Web Service WebService attribute -Allows you to specify the Web service’s namespace and description Namespace property -The namespace that the Web service uses Description property -Describe the Web service’s purpose - ConformsTo property Instructs Visual Web Developer to perform its “behind-the-scenes” work in conformance with to a certain guideline -By default, each new Web service class created in Visual Web Developer inherits from class System.Web.Services.WebService

 2006 Pearson Education, Inc. All rights reserved Defining the HugeInteger Web Service (Cont.) WebMethod attribute -Exposes a method so it can be called remotely -When this attribute is absent, the method is not accessible to the clients

 2006 Pearson Education, Inc. All rights reserved. 28 Outline HugeInteger.cs (1 of 7) Namespaces for Web services Assign the Web service’s namespace and description Indicates that the Web service conforms to Basic Profile 1.1 Web service class inherits from System.Web.Services. WebService Enable access to any digit in a HugeInteger

 2006 Pearson Education, Inc. All rights reserved. 29 Outline HugeInteger.cs (2 of 7)

 2006 Pearson Education, Inc. All rights reserved. 30 Outline HugeInteger.cs (3 of 7) Allows the method to be called by the client

 2006 Pearson Education, Inc. All rights reserved. 31 Outline HugeInteger.cs (4 of 7) Allows the method to be called by the client

 2006 Pearson Education, Inc. All rights reserved. 32 Outline HugeInteger.cs (5 of 7) Allows the method to be called by the client

 2006 Pearson Education, Inc. All rights reserved. 33 Outline HugeInteger.cs (6 of 7) Allows the method to be called by the client

 2006 Pearson Education, Inc. All rights reserved. 34 Outline HugeInteger.cs (7 of 7) Allows the method to be called by the client

 2006 Pearson Education, Inc. All rights reserved. 35 Common Programming Error 22.1 Failing to expose a method as a Web method by declaring it with the WebMethod attribute prevents clients of the Web service from accessing the method.

 2006 Pearson Education, Inc. All rights reserved. 36 Portability Tip 22.1 Specify a namespace for each Web service so that it can be uniquely identified by clients. In general, you should use your company’s domain name as the Web service’s namespace, since company domain names are guaranteed to be unique.

 2006 Pearson Education, Inc. All rights reserved. 37 Portability Tip 22.2 Specify descriptions for a Web service and its Web methods so that the Web service’s clients can view information about the service in the service’s ASMX page.

 2006 Pearson Education, Inc. All rights reserved. 38 Common Programming Error 22.2 No method with the WebMethod attribute can be declared static —for a client to access a Web method, an instance of that Web service must exist.

 2006 Pearson Education, Inc. All rights reserved Building a Web Service in Visual Web Developer To create an ASP.NET Web Service project that executes on your computer’s local IIS Web server: -Step 1: Create the Project Must be project of type ASP.NET Web Service -Step 2: Examine the Newly Created Project The code-behind file Service.cs contains code for a simple Web service -Step 3: Modify and Rename the Code-Behind File -Step 4: Examine the ASMX File -Step 5: Modify the ASMX File -Step 6: Rename the ASMX File

 2006 Pearson Education, Inc. All rights reserved. 40 Fig | Creating an ASP.NET Web Service in Visual Web Developer.

 2006 Pearson Education, Inc. All rights reserved. 41 Fig | Code view of a Web service.

 2006 Pearson Education, Inc. All rights reserved Deploying the HugeInteger Web Service Accessing the HugeInteger Web Service’s ASMX Page from Another Computer -Access the Web service’s ASMX page from your computer by typing the following URL in a Web browser in the form: -By deploying the Web service on an IIS Web server, a client can connect to that server to access the Web service with a URL of the form:

 2006 Pearson Education, Inc. All rights reserved Deploying the HugeInteger Web Service (Cont.) Accessing the HugeInteger Web Service’s ASMX Page When the Web Service Executes in Visual Web Developer’s Built-in Web Server -Web servers typically receive requests on port 80 -Visual Web Developer’s Web server receives requests on a randomly selected port number Ensure that Visual Web Developer’s built-in Web server does not conflict with another Web server running -Requests must be specify the port number as part of the request Except when on port 80 -The URL to access the HugeInteger Web service’s ASMX page would be of the form:

 2006 Pearson Education, Inc. All rights reserved. 44 Error-Prevention Tip 22.2 Update the Web service’s ASMX file appropriately whenever the name of a Web service’s code-behind file or the class name changes. Visual Web Developer creates the ASMX file, but does not automatically update it when you make changes to other files in the project.

 2006 Pearson Education, Inc. All rights reserved Creating a Client to Consume the HugeInteger Web Service Create a Windows application as the client using Visual C# 2005: -Step 1: Open the Add Web Reference Dialog (Fig ) -Step 2: Locate Web Services on Your Computer (Fig ) -Step 3: Choose the Web Service to Reference (Fig ) -Step 4: Add the Web Reference (Fig ) -Step 5: View the Web Reference in the Solution Explorer (Fig )

 2006 Pearson Education, Inc. All rights reserved. 46 Fig | Adding a Web service reference to a project.

 2006 Pearson Education, Inc. All rights reserved. 47 Fig | Add Web Reference dialog.

 2006 Pearson Education, Inc. All rights reserved. 48 Fig | Web services located on localhost.

 2006 Pearson Education, Inc. All rights reserved. 49 Fig | Web reference selection and description.

 2006 Pearson Education, Inc. All rights reserved. 50 Fig | Solution Explorer after adding a Web reference to a project.

 2006 Pearson Education, Inc. All rights reserved Creating a Client to Consume the HugeInteger Web Service (Cont.) Notes on Creating a Client to Consume a Web Service -Add the Web reference first So Visual C# 2005 can recognize an object of the Web service proxy class -Can access the Web service through an object of the proxy class -The proxy class is located in namespace localhost, so you must use localhost.class_name to reference this class -Must create an object of the proxy class to access the Web service -Do not need access to the proxy class’s code -Can invoke the proxy object’s methods as if it were an object of the Web service class -Two common technologies facilitate to locating a new Web service Universal Description, Discovery and Integration (UDDI) Discovery of Web services (DISCO)

 2006 Pearson Education, Inc. All rights reserved. 52 Outline UsingHugeInteger Service.cs (1 of 8) Declare variable of localhost.HugeInteger

 2006 Pearson Education, Inc. All rights reserved. 53 Outline UsingHugeInteger Service.cs (2 of 8) The proxy object is created and assigned to remoteInteger Invoke method of the Web service

 2006 Pearson Education, Inc. All rights reserved. 54 Outline UsingHugeInteger Service.cs (3 of 8) Invoke method of the Web service

 2006 Pearson Education, Inc. All rights reserved. 55 Outline UsingHugeInteger Service.cs (4 of 8) Invoke method of the Web service

 2006 Pearson Education, Inc. All rights reserved. 56 Outline UsingHugeInteger Service.cs (5 of 8) Invoke method of the Web service

 2006 Pearson Education, Inc. All rights reserved. 57 Outline UsingHugeInteger Service.cs (6 of 8) Invoke method of the Web service

 2006 Pearson Education, Inc. All rights reserved. 58 Outline UsingHugeInteger Service.cs (7 of 8)

 2006 Pearson Education, Inc. All rights reserved. 59 Outline UsingHugeInteger Service.cs (8 of 8)

 2006 Pearson Education, Inc. All rights reserved Session Tracking in Web Services Session Tracking -Eliminates the need for information to be passed between the client and the Web service multiple times Improves performance -Web methods can return personalized, localized results without requiring that the address be passed in each method call After the user’s address is stored in a session variable -Requires less effort on the part of the programmer Less information is passed in each method call

 2006 Pearson Education, Inc. All rights reserved Creating a Blackjack Web Service Web method’s EnableSession -Indicates that session information should be maintained and should be accessible to the method -Required only for methods that must access the session information

 2006 Pearson Education, Inc. All rights reserved. 62 Outline BlackjackService.cs (1 of 5) Assign the Web service’s namespace and description Indicates that the Web service conforms to Basic Profile 1.1 Indicates that session information should be maintained and accessible to this method Obtains the current user’s deck as an ArrayList from the Web service’s Session object

 2006 Pearson Education, Inc. All rights reserved. 63 Outline BlackjackService.cs (2 of 5) Indicates that session information should be maintained and accessible to this method Adds the ArrayList to the Session object to maintain the deck between method calls from a particular client

 2006 Pearson Education, Inc. All rights reserved. 64 Outline BlackjackService.cs (3 of 5) Allows the method to be called by the client

 2006 Pearson Education, Inc. All rights reserved. 65 Outline BlackjackService.cs (4 of 5)

 2006 Pearson Education, Inc. All rights reserved. 66 Outline BlackjackService.cs (5 of 5)

 2006 Pearson Education, Inc. All rights reserved Consuming the Blackjack Web Service CookieContainer -Namespace System.Net -Stores the information from a cookie in a Cookie object -Without creating a CookieContainer object, the Web service would create a new Session object for each request The user’s state information would not persist across requests Cookie -Contains a unique identifier that the Web service can use to recognize the client when the client makes future requests -The cookie is automatically sent back to the server as part of each request

 2006 Pearson Education, Inc. All rights reserved. 68 Outline Blackjack.cs (1 of 16) Create an instance of BlackjackService to represent dealer

 2006 Pearson Education, Inc. All rights reserved. 69 Outline Blackjack.cs (2 of 16) Instantiate the “dealer” Create a new CookieContainer object for the dealer’s CookieContainer property

 2006 Pearson Education, Inc. All rights reserved. 70 Outline Blackjack.cs (3 of 16)

 2006 Pearson Education, Inc. All rights reserved. 71 Outline Blackjack.cs (4 of 16) Invoke method of the Web service

 2006 Pearson Education, Inc. All rights reserved. 72 Outline Blackjack.cs (5 of 16)

 2006 Pearson Education, Inc. All rights reserved. 73 Outline Blackjack.cs (6 of 16)

 2006 Pearson Education, Inc. All rights reserved. 74 Outline Blackjack.cs (7 of 16)

 2006 Pearson Education, Inc. All rights reserved. 75 Outline Blackjack.cs (8 of 16) Invoke method of the Web service

 2006 Pearson Education, Inc. All rights reserved. 76 Outline Blackjack.cs (9 of 16) Invoke method of the Web service

 2006 Pearson Education, Inc. All rights reserved. 77 Outline Blackjack.cs (10 of 16) Invoke method of the Web service

 2006 Pearson Education, Inc. All rights reserved. 78 Outline Blackjack.cs (11 of 16)

 2006 Pearson Education, Inc. All rights reserved. 79 Outline Blackjack.cs (12 of 16) a) Initial cards dealt to the player and the dealer when the user pressed the Deal button

 2006 Pearson Education, Inc. All rights reserved. 80 Outline Blackjack.cs (13 of 16) b) Cards after the player pressed the Hit button twice, then the Stay button. In this case, the player won the game with a higher total than the dealer.

 2006 Pearson Education, Inc. All rights reserved. 81 Outline Blackjack.cs (14 of 16) c) Cards after the player pressed the Hit button once, then the Stay button. In this case, the player busted (exceeded 21) and the dealer won the game.

 2006 Pearson Education, Inc. All rights reserved. 82 Outline Blackjack.cs (15 of 16) d) Cards after the player pressed the Deal button. In this case, the player won with Blackjack because the first two cards were an ace and a card with a value of 10 (a jack in this case.)

 2006 Pearson Education, Inc. All rights reserved. 83 Outline Blackjack.cs (16 of 16) e) Cards after the player pressed the Stay button. In this case, the player and dealer push — they have the same card total.

 2006 Pearson Education, Inc. All rights reserved Using Web Forms and Web Services Using DataSet Designer to add a DataSet to a project -Automatically create DataSet and TableAdapter objects for you

 2006 Pearson Education, Inc. All rights reserved. 85 Outline Reservation Service.cs (1 of 2) Assign the Web service’s namespace and description Allows the method to be called by the client Query the database

 2006 Pearson Education, Inc. All rights reserved. 86 Outline Reservation Service.cs (2 of 2) Update the database

 2006 Pearson Education, Inc. All rights reserved Adding Data Components to a Web Services The following steps for configuring the DataSet and its corresponding TableAdapter using the airline reservation example: -Step 1: Create ReservationService and Add a DataSet to the Project -Step 2: Select the Data Source and Create a Connection -Step 3: Open the Query Builder and Add the Seats Table from Tickets.mdf -Step 4: Configure a SELECT Query to Obtain Available Seats -Step 5: Add Another Query to the SeatsTableAdapter for the TicketsDataSet -Step 6: Configure an UPDATE Statement to Reserve a Seat

 2006 Pearson Education, Inc. All rights reserved. 88 Fig | QueryBuilder dialog specifying a SELECT query that selects seats that are not already reserved and that match a particular type and class.

 2006 Pearson Education, Inc. All rights reserved. 89 Fig | QueryBuilder dialog specifying an UPDATE statement that reserves a seat.

 2006 Pearson Education, Inc. All rights reserved. 90 Outline ReservationClient.aspx (1 of 2)

 2006 Pearson Education, Inc. All rights reserved. 91 Outline ReservationClient.aspx (2 of 2) Button to submit requests after making selections Defines an initially blank Label which displays an appropriate message if no seat matching the user’s selection is available

 2006 Pearson Education, Inc. All rights reserved. 92 Outline ReservationClient.aspx.cs (1 of 2) Create a ReservationService proxy object

 2006 Pearson Education, Inc. All rights reserved. 93 Outline ReservationClient.aspx.cs (2 of 2) Invoke Web method to determine if seat is available Display the appropriate output based on the Web method’s result

 2006 Pearson Education, Inc. All rights reserved. 94 Fig | Ticket reservation Web Form sample execution. (Part 1 of 2.) a) Selecting a seat. b) Seat reserved successfully

 2006 Pearson Education, Inc. All rights reserved. 95 Fig | Ticket reservation Web Form sample execution. (Part 2 of 2.) c) Attempting to reserve another seat. d) No seats match the requested type and class.

 2006 Pearson Education, Inc. All rights reserved User-Defined Types in Web Services Custom Types -Web methods can also return process user-defined types in a Web service -Web service clients can use these user-defined types The proxy class created for the client contains the type definitions Serialization of User-Defined Types -Custom types that are sent to or from a Web service are serialized Enable them to be passed in XML format -Referred to as XML serialization

 2006 Pearson Education, Inc. All rights reserved User-Defined Types in Web Services (Cont.) Requirements for User-Defined Types Used with Web Methods -Must provide a public default constructor Must be able to call this constructor as part of the process of deserializing the object when a Web service receives an XML serialized object -Properties and instance variables that should be serialized in XML format must be declared public -Properties that should be serialized must provide both get and set accessors Read-only properties are not serialized Any data that is not serialized simply receives its default value when an object of the class is deserialized

 2006 Pearson Education, Inc. All rights reserved. 98 Common Programming Error 22.3 Failure to define a default or parameterless public constructor for a type being passed to or returned from a Web method is a runtime error.

 2006 Pearson Education, Inc. All rights reserved. 99 Common Programming Error 22.4 Defining only the get or set accessor of a property for a user-defined type being passed to or returned from a Web method results in a property that is inaccessible to the client.

 2006 Pearson Education, Inc. All rights reserved. 100 Software Engineering Observation 22.1 Clients of a Web service can access only the service’s public members. The programmer can provide public properties to allow access to private data.

 2006 Pearson Education, Inc. All rights reserved. 101 Outline Equation.cs (1 of 5) Declare the required parameterless constructor Calls the three argument constructor

 2006 Pearson Education, Inc. All rights reserved. 102 Outline Equation.cs (2 of 5)

 2006 Pearson Education, Inc. All rights reserved. 103 Outline Equation.cs (3 of 5) set accessors are required even if it means having empty bodies

 2006 Pearson Education, Inc. All rights reserved. 104 Outline Equation.cs (4 of 5)

 2006 Pearson Education, Inc. All rights reserved. 105 Outline Equation.cs (5 of 5)

 2006 Pearson Education, Inc. All rights reserved. 106 Outline Generator.cs (1 of 2) Allows the method to be called by the client

 2006 Pearson Education, Inc. All rights reserved. 107 Outline Generator.cs (2 of 2) Passes the string operation received by GenerateEquation to the Equation constructor Return the created Equation object

 2006 Pearson Education, Inc. All rights reserved. 108 Fig | Returning an XML serialized object from a Web method. (Part 1 of 2.) a) Invoking the GenerateEquation method to create a subtraction equation with two-digit numbers.

 2006 Pearson Education, Inc. All rights reserved. 109 Fig | Returning an XML serialized object from a Web method. (Part 2 of 2.) b) XML encoded results of invoking the GenerateEquation method to create a subtraction equation with two-digit numbers.

 2006 Pearson Education, Inc. All rights reserved. 110 Outline MathTutor.cs (1 of 6) Create objects of Equation and Generator from the localhost Invoke GenerateEquation and assign the return object to equation

 2006 Pearson Education, Inc. All rights reserved. 111 Outline MathTutor.cs (2 of 6) Call equation ’s properties

 2006 Pearson Education, Inc. All rights reserved. 112 Outline MathTutor.cs (3 of 6)

 2006 Pearson Education, Inc. All rights reserved. 113 Outline MathTutor.cs (4 of 6)

 2006 Pearson Education, Inc. All rights reserved. 114 Outline MathTutor.cs (5 of 6) a) Generating a level 1 addition equation.

 2006 Pearson Education, Inc. All rights reserved. 115 Outline MathTutor.cs (6 of 6) d) Generating a level 2 multiplication equation. c) Answering the equation correctly. b) Answering the equation incorrectly.