- •Preface
- •Who Should Read This Book
- •Organization and Presentation
- •Contacting the Authors
- •Acknowledgments
- •Contents
- •Introduction
- •Why Microsoft .NET?
- •The Microsoft .NET Architecture
- •Internet Standards
- •The Evolution of ASP
- •The Benefits of ASP.NET
- •What Is .NET?
- •.NET Experiences
- •.NET Clients
- •.NET Services
- •.NET Servers
- •Review
- •Quiz Yourself
- •Installation Requirements
- •Installing ASP.NET and ADO.NET
- •Installing the .NET Framework SDK
- •Testing Your Installation
- •Support for .NET
- •Review
- •Quiz Yourself
- •Designing a Database
- •Normalization of Data
- •Security Considerations
- •Review
- •Quiz Yourself
- •Creating a Database
- •Creating SQL Server Tables
- •Creating a View
- •Creating a Stored Procedure
- •Creating a Trigger
- •Review
- •Quiz Yourself
- •INSERT Statements
- •DELETE Statements
- •UPDATE Statements
- •SELECT Statements
- •Review
- •Quiz Yourself
- •The XML Design Specs
- •The Structure of XML Documents
- •XML Syntax
- •XML and the .NET Framework
- •Review
- •Quiz Yourself
- •ASP.NET Events
- •Page Directives
- •Namespaces
- •Choosing a Language
- •Review
- •Quiz Yourself
- •Introducing HTML Controls
- •Using HTML controls
- •How HTML controls work
- •Intrinsic HTML controls
- •HTML Control Events
- •The Page_OnLoad event
- •Custom event handlers
- •Review
- •Quiz Yourself
- •Intrinsic Controls
- •Using intrinsic controls
- •Handling intrinsic Web control events
- •List Controls
- •Rich Controls
- •Review
- •Quiz Yourself
- •Creating a User Control
- •Adding User Control Properties
- •Writing Custom Control Methods
- •Implementing User Control Events
- •Review
- •Quiz Yourself
- •Common Aspects of Validation Controls
- •Display property
- •Type Property
- •Operator Property
- •Using Validation Controls
- •RequiredFieldValidator
- •RegularExpressionValidator
- •CompareValidator
- •RangeValidator
- •CustomValidator
- •ValidationSummaryx
- •Review
- •Quiz Yourself
- •Maintaining State Out of Process for Scalability
- •No More Cookies but Plenty of Milk!
- •Out of Process State Management
- •Review
- •Quiz Yourself
- •Introducing the Key Security Mechanisms
- •Web.config and Security
- •Special identities
- •Using request types to limit access
- •New Tricks for Forms-based Authentication
- •Using the Passport Authentication Provider
- •Review
- •Quiz Yourself
- •ASP.NET Updates to the ASP Response Model
- •Caching with ASP.NET
- •Page Output Caching
- •Absolute cache expiration
- •Sliding cache expiration
- •Fragment Caching
- •Page Data Caching
- •Expiration
- •File and Key Dependency and Scavenging
- •Review
- •Quiz Yourself
- •A Brief History of Microsoft Data Access
- •Differences between ADO and ADO.NET
- •Transmission formats
- •Connected versus disconnected datasets
- •COM marshaling versus text-based data transmission
- •Variant versus strongly typed data
- •Data schema
- •ADO.NET Managed Provider Versus SQL Managed Provider
- •Review
- •Quiz Yourself
- •Review
- •Quiz Yourself
- •Creating a Connection
- •Opening a Connection
- •Using Transactions
- •Review
- •Quiz Yourself
- •Building a Command
- •Connection property
- •CommandText property
- •CommandType property
- •CommandTimeout property
- •Appending parameters
- •Executing a Command
- •ExecuteNonQuery method
- •Prepare method
- •ExecuteReader method
- •Review
- •Quiz Yourself
- •Introducing DataReaders
- •Using DataReader Properties
- •Item property
- •FieldCount property
- •IsClosed property
- •RecordsAffected property
- •Using DataReader Methods
- •Read method
- •GetValue method
- •Get[Data Type] methods
- •GetOrdinal method
- •GetName method
- •Close method
- •Review
- •Quiz Yourself
- •Constructing a DataAdapter Object
- •SelectCommand property
- •UpdateCommand, DeleteCommand, and InsertCommand properties
- •Fill method
- •Update method
- •Dispose method
- •Using DataSet Objects
- •DataSetName property
- •CaseSensitive property
- •Review
- •Quiz Yourself
- •Constructing a DataSet
- •Tables property
- •TablesCollection Object
- •Count property
- •Item property
- •Contains method
- •CanRemove method
- •Remove method
- •Add method
- •DataTable Objects
- •CaseSensitive property
- •ChildRelations property
- •Columns property
- •Constraints property
- •DataSet property
- •DefaultView property
- •ParentRelations property
- •PrimaryKey property
- •Rows property
- •Dispose method
- •NewRow method
- •Review
- •Quiz Yourself
- •What Is Data Binding?
- •Binding to Arrays and Extended Object Types
- •Binding to Database Data
- •Binding to XML
- •TreeView Control
- •Implement the TreeView server control
- •Review
- •Quiz Yourself
- •DataGrid Control Basics
- •Binding a set of data to a DataGrid control
- •Formatting the output of a DataGrid control
- •Master/Detail Relationships with the DataGrid Control
- •Populating the Master control
- •Filtering the detail listing
- •Review
- •QUIZ YOURSELF
- •Updating Your Data
- •Handling the OnEditCommand Event
- •Handling the OnCancelCommand Event
- •Handling the OnUpdateCommand Event
- •Checking that the user input has been validated
- •Executing the update process
- •Deleting Data with the OnDeleteCommand Event
- •Sorting Columns with the DataGrid Control
- •Review
- •Quiz Yourself
- •What Is Data Shaping?
- •Why Shape Your Data?
- •DataSet Object
- •Shaping Data with the Relations Method
- •Review
- •Quiz Yourself
- •OLEDBError Object Description
- •OLEDBError Object Properties
- •OLEDBError Object Methods
- •OLEDBException Properties
- •Writing Errors to the Event Log
- •Review
- •Quiz Yourself
- •Introducing SOAP
- •Accessing Remote Data with SOAP
- •SOAP Discovery (DISCO)
- •Web Service Description Language (WSDL)
- •Using SOAP with ASP.NET
- •Review
- •Quiz Yourself
- •Developing a Web Service
- •Consuming a Web Service
- •Review
- •Quiz Yourself
- •ASP and ASP.NET Compatibility
- •Scripting language limitations
- •Rendering HTML page elements
- •Using script blocks
- •Syntax differences and language modifications
- •Running ASP Pages under Microsoft.NET
- •Using VB6 Components with ASP.NET
- •Review
- •Quiz Yourself
- •Preparing a Migration Path
- •ADO and ADO.NET Compatibility
- •Running ADO under ASP.NET
- •Early Binding ADO COM Objects in ASP.NET
- •Review
- •Quiz Yourself
- •Answers to Part Reviews
- •Friday Evening Review Answers
- •Saturday Morning Review Answers
- •Saturday Afternoon Review Answers
- •Saturday Evening Review Answers
- •Sunday Morning Review Answers
- •Sunday Afternoon Review Answers
- •What’s on the CD-ROM
- •System Requirements
- •Using the CD with Windows
- •What’s on the CD
- •The Software Directory
- •Troubleshooting
- •ADO.NET Class Descriptions
- •Coding Differences in ASP and ASP.NET
- •Retrieving a Table from a Database
- •Displaying a Table from a Database
- •Variable Declarations
- •Statements
- •Comments
- •Indexed Property Access
- •Using Arrays
- •Initializing Variables
- •If Statements
- •Case Statements
- •For Loops
- •While Loops
- •String Concatenation
- •Error Handling
- •Conversion of Variable Types
- •Index
S E S S I O N
27
SOAP It Up!
Session Checklist
Using SOAP in the .NET Platform
Using SOAP in a heterogeneous computing environment
In this session, we discuss how the ASP.NET platform is incorporating at its core the adoption of open Internet standards to support interoperability across distributed heterogeneous computing environments. With ASP.NET you can implement Web Services,
which enable you to build distributed applications that expose your business logic to any application client regardless of the operating system, programming language, or object model it is built on. A key standard that is critical to this approach is the SOAP specification, which supports the invocation of business objects across the Internet or an intranet regardless of the client or the server’s operating platform and without requiring any proprietary software on either side of the communication.
Introducing SOAP
SOAP (Simple Object Access Protocol) is a wire protocol specification for invoking methods, on servers, services, components, and objects. As the Internet expands to deliver an everincreasing set of services and applications, communication between numerous different platforms, such as CORBA and COM, is critical to support the evolving needs of application- to-application communication in Business-to-Business (B2B), Business-to-Commerce (B2C), and Business-to-Everyone (B2E) environments.
Before SOAP, if you had a business component written as a Java Servlet that supported the lookup and publication of data, it was basically impossible to instantiate that object with a COM-based business component running on the opposite side of a firewall. The Java servlet built on the CORBA platform would typically require the use of the Object Management Group’s Internet Inter-ORB Protocol (IIOP) to facilitate distributed application interaction, whereas the COM component would use COM Internet Services (CIS) plus
278 |
Sunday Afternoon |
Distributed Component Object Model (DCOM), Remote Data Services (RDS), or Remote Scripting to communicate with distributed objects, thus providing no simple or efficient way for consumer or provider applications to communicate easily across the Internet through proxy servers and firewalls.
SOAP was submitted to the W3C by Microsoft, IBM, DevelopMentor, and UserLand among others to address these issues. There are two major stated goals of the SOAP specification:
Provide a standard object invocation protocol built on Internet standards, using HTTP as the transport protocol and XML for the data encoding.
Create an extensible protocol and payload format that can evolve over time.
SOAP eliminates a lot of the complexity associated with the other distributed object invocation solutions, such as DCOM and IIOP, by simply not specifying how issues such as garbage collection, type safety, versioning, object by reference, and other similar communication issues should be handled. Instead it focuses on simply defining the mechanism to pass commands and parameters between HTTP clients and servers regardless of the operating system, programming language, or object model used on either side of the communication.
Early product implementations of SOAP illustrate the broad diversity of object models, platforms, and programming languages. These include:
Nouveau ORB by Rogue Wave
Orbix 2000 by Iona
Voyager by ObjectSpace
Frontier Groupware by UserLand
Windows DNA by Microsoft
Accessing Remote Data with SOAP
Let’s look at an example of how the SOAP specification allows two applications to operate across firewalls to provide services to one another. We will examine a theoretical Web site, www.soapitup.com, which provides personalized portal pages for its customers. The site runs on a Sun Solaris platform using Java Servlets to support the delivery of customized stock quotes and research to its customers.
Another site, www.stockquoteserver.com, is a service that provides realtime stock quotes, volume and trade data, and other information as a B2B service. This site operates on a Windows 2000-based architecture using an ASP.NET solution to provide its service.
www.soapitup.com would like to access the GetQuote method of the StockQuote Service on the www.stockquoteserver.com site, and then return the results of the service to www.soapitup.com end users.
Prior to the SOAP application this type of communication for anything but the most simplistic of calls would have been extremely difficult and time consuming to develop as the applications are operating on two distinct object models, CORBA and COM.
With SOAP, however, this heterogeneous environment can communicate easily, allowing the Java Servlets to activate the COM objects on www.stockquoteserver.com with ease.
Session 27—SOAP It Up! |
279 |
Figure 27-1 illustrates how a www.soapitup.com customer would access the www.soapitup.com Web site and be provided with a stock quote that was retrieved by www.soapitup.com from www.stockquoteserver.com.
1) Client visits www.soapitup.com and requests a stock quote
9) Client Receives
HTML Page with Result
HTTP + HTML HTTP + HTML
Internet
HTTP + HTML
HTTP + XML
http://www.soapitup.com
•Sun Solaris Platform
•Java Server Pages
stockquote.jsp page
2)Receives request to get quote for IBM from end user
3)Page creates stock proxy object
SOAP Client Proxy: Getquote()
4) Converts call to HTTP and XML per SOAP Specification and Posts to http:// www.stockquote.com/Stockquote.asmx
10) Proxy receives results in XML over HTTP converts to function return value of $110.25
8) Accepts results from Proxy and displays results to user in HTML page.
HTTP + XML
HTTP + XML
Firewall allowing only Port80 Traffic
http://www.stockquote.com
•Windows 2000 Platform
•Active Server Pages
stockquote.asmx page
5)HTTP request arrives from www.soapitup.com/ stockquote.jsp, parameters encoded in XML
6)ASP.NET Calls Method GetQuote()
Function GetQuote(StockSymbol as String)
Retrieves Stock Value from SQL Server Returns Stock Value as Integer
End Method
7) ASP.NET formats and returns results as SOAP return via XML and HTTP
Figure 27-1 Illustration of SOAP request in heterogeneous environment
Figure 27-1 illustrates each of the steps that occur in a SOAP Communication. Lets look at each step below:
1.First, a customer opens the stockquote.jsp page on the www.soapitup.com WebWeb site. The user requests a stock quote by entering a stock name and hitting the submit button.
2.Next, the stockquote.jsp page captures the stock symbol from the user.
3.The stockquote.jsp page then invokes a client proxy for the www.stockquoteserver.com GetQuote object.
4.This proxy will generate a SOAP client request and encapsulate it in an HTTP POST as follows:
POST /StockQuote.asmx HTTP/1.1
Host: www.stockquoteserver.com
Content-Type: text/xml; charset=”utf-8”
280 |
Sunday Afternoon |
Content-Length: nnn
<SOAP-ENV:Envelope>
<SOAP-ENV:Body>
<m:GetQuote xmlns:m=”Some-Namespace-URI”>
<symbol>IBM</symbol>
</m:GetQuote>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The first four lines are standard HTTP, indicating a posting of the content to http://www.stockquoteserver.com/StockQuote.asmx. The content type is defined as text/xml, which lets the server know that the payload is going to be sent as an XML message.
SOAP defines two types of messages, Call and Response, in order to allow clients to invoke a remote procedure and allow the called procedure on the server to respond with appropriate values.
The Call example above defines the envelope and body in a standard XML structure that clearly indicates we are accessing the GetQuote method and passing the value IBM as the parameter.
5.Because this request is a standard HTTP POST that embeds XML, there are no issues passing this request across the firewall protecting the www.stockquoteserver.com site.
6.Once the stockquote.asmx page receives the request, it can quickly decipher the XML structure of the request and call the GetQuote method and pass the value IBM as the parameter.
Note
Because the SOAP specification doesn’t describe how the provider service should call its respective methods, the only constraint on the provider’s choice of language or operating system is that it support the SOAP wire protocol.
7.Once the value is retrieved, a SOAP response message is created as follows:
HTTP/1.1 200 OK
Content-Type: text/xml; charset=”utf-8”
Content-Length: nnnn
<SOAP-ENV:Envelope>
<SOAP-ENV:Body>
<m:GetQuoteResponse xmlns:m=”Some-Namespace-URI”>
<result>110</result>
</m:GetQuoteResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>