PDF Chapter 6 Web Services - J. Mack Robinson College of Business

McGraw-Hill

6-1

? 2007 The McGraw-Hill Companies, Inc. All rights reserved.

Chapter

6

Web Services

This chapter discusses the requirements and technologies for creating a Web Service and demonstrates how to access the Web Service after

it is created.

Objectives

Discuss the concepts of Web services and understand the terminology

Create a Web service Add a Web reference to a Windows project Consume a Web service from a Windows project Perform calculations in a Web service Access data through a Web service Consume a third-party Web service

McGraw-Hill

6-3

? 2007 The McGraw-Hill Companies, Inc. All rights reserved.

1

Concepts and Terminology

When a component is created as a Web Service many other services and technologies are required, and include:

XML, SOAP, WSDL, UDDI

Think of each of the technologies as protocols or rules to store, locate and use Web services

Web services can be created and consumed using many languages and platforms--not all Web services use XML--Web services created with VS should more accurately be referred to as XML Web Services.

McGraw-Hill

6-4

? 2007 The McGraw-Hill Companies, Inc. All rights reserved.

XML

A standard method for storing data that can be transferred easily from one machine or platform to another

Key advantage for Web services is that data are transmitted in a text format rather than in binary-- allowing data to pass through many firewalls

McGraw-Hill

6-5

? 2007 The McGraw-Hill Companies, Inc. All rights reserved.

SOAP

Simple Object Access Protocol (SOAP) is the emerging standard for sending data

Includes a set of rules for handling requests and responses including class names, method names, and parameters

SOAP works with XML but does not include a specific protocol for transporting the response and request packets The transport protocol is most frequently HTTP

McGraw-Hill

6-6

? 2007 The McGraw-Hill Companies, Inc. All rights reserved.

2

WDSL

Web Services Description Language (WSDL) provides the format of the calls to the methods in Web services

Contains information about the names of methods, the parameters that can be passed, and the values that are returned from the functions

There is an automatically generated .wsdl file in the Web References folder of a project that consumes a Web service

McGraw-Hill

6-7

? 2007 The McGraw-Hill Companies, Inc. All rights reserved.

UDDI

Universal Description, Discovery, and Integration (UDDI) is often called a directory service for Web services

Use to search for available Web services and determine their functionality

McGraw-Hill

6-8

? 2007 The McGraw-Hill Companies, Inc. All rights reserved.

URI

Universal Resource Identifier (URI) uniquely identifies a resource on the Web and is somewhat more generic than the older term, URL

McGraw-Hill

6-9

? 2007 The McGraw-Hill Companies, Inc. All rights reserved.

3

Creating a Web Service

Select the location and name the new Web service in the New Web Site dialog box

The project does not have a user interface but opens with the code in the editor

A Web service may hold server connections, data components, other components from the toolbox, and written methods

McGraw-Hill

6-10

? 2007 The McGraw-Hill Companies, Inc. All rights reserved.

Attribute Tags

These attributes are used to generate the metadata for the Web service and identify the method as available from a consumer application

The WebService attribute includes the default URI, which is the default target namespace for the service

The function header is preceded by an attribute tag-- makes the method available to consumers of the Web service

PPuubblilcicFFuunnccttioionnHHeellloloWWoorrldld(())AAssSSttrriningg

McGraw-Hill

6-11

? 2007 The McGraw-Hill Companies, Inc. All rights reserved.

Testing a Web Service

Right-click the .asmx file name (FirstService.asmx) in the Solution Explorer and select Set as Start Page, press Ctrl+F5 which is the shortcut for Start Without Debugging

VS IDE compiles the code and runs it in a sample test page in the browser

The test page displays the name of your class and a link to the method

McGraw-Hill

6-12

? 2007 The McGraw-Hill Companies, Inc. All rights reserved.

4

Attribute Properties

The values inside the parentheses for an attribute are properties of the attribute Example:

Optional properties for the WebMethod attribute can be set--this technique for assigning a value to a property is called using a named parameter

McGraw-Hill

6-13

? 2007 The McGraw-Hill Companies, Inc. All rights reserved.

Create a Project with a Web Reference

Although projects to consume the Web service can be placed anywhere, it's best to keep projects together in the same solution during testing

The solution name must appear in the Solution Explorer, which is not the default. Select Tools/Options/Projects and Solutions/General and selection the option to Always show solution

In the Solution Explorer, select the solution name, right-click and select Add/New Project, select the Windows Application template and name it

McGraw-Hill

6-14

? 2007 The McGraw-Hill Companies, Inc. All rights reserved.

Web Reference

A.

B.

C. D.

New folder created in Solutions Explorer

McGraw-Hill

6-15

? 2007 The McGraw-Hill Companies, Inc. All rights reserved.

5

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download