Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: " 2006 Pearson Education, Inc. All rights reserved. 1 22 Web Services."— Presentation transcript:

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

2  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

3  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.

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

5  2006 Pearson Education, Inc. All rights reserved. 5 22.4.4Creating a Client to Consume the HugeInteger Web Service 22.4.5 Consuming the HugeInteger Web Service 22.5Session Tracking in Web Services 22.5.1Creating a Blackjack Web Service 22.5.2Consuming the Blackjack Web Service 22.6Using Web Forms and Web Services 22.6.1Adding Data Components to a Web Service 22.6.2Creating 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

6  2006 Pearson Education, Inc. All rights reserved. 6 22.1 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

7  2006 Pearson Education, Inc. All rights reserved. 7 22.2.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

8  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.

9  2006 Pearson Education, Inc. All rights reserved. 9 22.2.1 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

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

11  2006 Pearson Education, Inc. All rights reserved. 11 22.2.2 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

12  2006 Pearson Education, Inc. All rights reserved. 12 22.2.3 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

13  2006 Pearson Education, Inc. All rights reserved. 13 22.2.3 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

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

15  2006 Pearson Education, Inc. All rights reserved. 15 22.2.4 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

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

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

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

19  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.

20  2006 Pearson Education, Inc. All rights reserved. 20 22.2.5 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

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

22  2006 Pearson Education, Inc. All rights reserved. 22 22.3 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

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

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

25  2006 Pearson Education, Inc. All rights reserved. 25 22.4 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

26  2006 Pearson Education, Inc. All rights reserved. 26 22.4.1 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

27  2006 Pearson Education, Inc. All rights reserved. 27 22.4.1 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

28  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

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

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

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

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

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

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

35  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.

36  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.

37  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.

38  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.

39  2006 Pearson Education, Inc. All rights reserved. 39 22.4.2 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

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

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

42  2006 Pearson Education, Inc. All rights reserved. 42 22.4.3 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: http://localhost/HugeInteger/HugeInteger.asmx -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: http://host/HugeInteger/HugeInteger.asmx

43  2006 Pearson Education, Inc. All rights reserved. 43 22.4.3 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: http://host:portNumber/HugeInteger/HugeInteger.asmx

44  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.

45  2006 Pearson Education, Inc. All rights reserved. 45 22.4.4 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. 22.12) -Step 2: Locate Web Services on Your Computer (Fig. 22.13) -Step 3: Choose the Web Service to Reference (Fig. 22.14) -Step 4: Add the Web Reference (Fig. 22.15) -Step 5: View the Web Reference in the Solution Explorer (Fig. 22.16)

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

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

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

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

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

51  2006 Pearson Education, Inc. All rights reserved. 51 22.4.4 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)

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

53  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

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

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

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

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

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

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

60  2006 Pearson Education, Inc. All rights reserved. 60 22.5 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

61  2006 Pearson Education, Inc. All rights reserved. 61 22.5.1 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

62  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

63  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

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

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

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

67  2006 Pearson Education, Inc. All rights reserved. 67 22.5.2 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

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

69  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

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

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

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

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

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

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

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

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

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

79  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

80  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.

81  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.

82  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.)

83  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.

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

85  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

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

87  2006 Pearson Education, Inc. All rights reserved. 87 22.6.1 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

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

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

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

91  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

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

93  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

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

95  2006 Pearson Education, Inc. All rights reserved. 95 Fig. 22.25 | 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.

96  2006 Pearson Education, Inc. All rights reserved. 96 22.7 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

97  2006 Pearson Education, Inc. All rights reserved. 97 22.7 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

98  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.

99  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.

100  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.

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

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

103  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

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

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

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

107  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

108  2006 Pearson Education, Inc. All rights reserved. 108 Fig. 22.28 | 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.

109  2006 Pearson Education, Inc. All rights reserved. 109 Fig. 22.28 | 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.

110  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

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

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

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

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

115  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.


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

Similar presentations


Ads by Google