XML is now an established technology for the description and transportation of data, and has made a major impact on almost every aspect of software development. When Microsoft introduced the .NET Framework, it took advantage of XML wherever it could. No other technology is so tightly bound with .NET as XML, both at the developer level and underlying the whole framework.
This book aims to give the reader enough information to be able to use XML from within the .NET Framework in the most efficient manner possible. It will explain in detail the usage of all the XML-related .NET Framework library classes for' the manipulation, validation, transformation, and serialization of XML data, using both Cfi' and Visual Basic .NET. It also looks at how the developer can utilize the full power of XML within the .NET Framework, for example, with the new XML capabilities of ADO. NET and ASP. NET. As is demonstrated, the .NET Framework itself uses XML, in configuration files, meta data, and Cfi''s XML code documentation mechanism, for example.
Who is this Book for?
This book is aimed at intermediate-level programmers who have started on their journey towards .NET development, and who want to see how to use XML within their .NET applications to its best advantage. Basic knowledge of C# or Visual Basic .NET, XML, and XML related technologies (XSLT, X?ath, and XML Schemas) is necessary. What does this Book Cover?
Reading and writing XML
DOM navigation and XSL transformations of XML
Validating and serializing XML
MSXML vs. System.XmL
ADO. NET and ASRNET XML support
Web Services and SOAP
C# code documentation
Introduction
Who Is This Book For?
What Does This Book Cover?
What You Need to Use This Book
Conventions
Customer Support
How to Download the Sample Code for the Book
Errata
E-mail Support
p2p.wrox.com
Why this System Offers the Best Support
Chapter 1: .NET Framework Overview
.NET Framework
Common Language Runtime
Managed Code
Common Language Specification (CLS)
Garbage Collection
What is an Assembly?
Application Domains
Framework Security
Application Deployment
Configuring Applications
COM rnteroperability
Framework Classes
.NET Languages
Introducing C#
C# Syntax
VB .NET Overview
VB. NET syntax
C# vs. VB.NET
ASP.NET
HTML Controls
Web Controls
Validation Controls
Data binding
Mobile Controls
Web Services
Application Directives
Server-Side Object Tags
Server-Side Includes
ADO.NET
Data Access
ADO vs. ADO.NET
XML and ADO.NET
Summary
Chapter 2: XML in the .NET Framework
.INI Files, then Registry Now?
Benefits of using XML Configuration Files
Types of Configuration Files
Application Configuration Files
Machine or Server Configuration File
Security Configuration Files
Configuration File XML Structure
.exe Application Configuration Files
ASP.NET Applications Configuration Files
XML Code Documentation
Visual Studio .NET and XML Documentation
ADO,NET, Data, and XML
ADO Limitations
Enter ADO.NET
ASP.NET and XML
Web Services
XML Serialization
Streaming and DOM-based XML Classes
Introducing System.Xml
XmlReader and XmlWriter
DOM, XPath, and XSLT
MSXML in .NET
Summary
Chapter 3: Reading and Writing XML
Technologies Used
The System,Xml Assembly
Reading XML Documents
The XmlReader Abstract Class
How Does XmlReader Compare to SAX?
The XmlTextReader Class
Constructing an Instance of XmlTextReader
Stepping Through an XML Document
The XmlNodeReader Class
The XmlValidatingReader Class
Writing XML Documents
The XmlWriter Abstract Class
The XmlTextWriter Class
Constructing an Instance of XmlTextWriter
Writing Data to an XmlTextWriter
A More Complex Example
The Problem
Our Solution: Encapsulate a Reader and a Writer
Summary
Chapter 4: DOM Navigation of XML
Technologies Used
The System. Xml Assembly
Understanding the DOM Classes
Document Representation
Usage Guidelines
Opening an Existing Document
Opening a Document from a URL
Opening a Document from a File
Opening a Document from a String in Memory
Navigating Through the Document
Searching for Content in the Document
GetElementsByTagNameO
GetElementByldO
SelectNodesO
SelectSingleNodeO
Accessing Content
Elements
Text
Comments
Processing instructions
Attributes
Entity Handling
Whitespace Handling
Namespace Support
Validation
Modifying a Document
Deleting Content
Modifying Content
Creating New Content
Inserting Content
Adding Attributes
Creating a Document from Scratch
A More Complex Example
The Business Problem
The Solution: Extend the XmlDocument Class
Summary
Chapter S: XSL Transformations of XML
Technologies Used
The System.Xml.Xsl Namespace
The System.Xml.XPath Namespace
XSLT Processing
The XslTransform Class
Loading a Stylesheet
Transforming XML Documents
Using Embedded Scripting with msxsl:script
Passing Arguments to a Transformation
Extending Stylesheets with Extension Objects
Tuning XSLT Transformations for Performance
Avoid Multiple Leads of Stylesheets
Use XPathDocument Objects
Use Smart Pipelining
Other XPath Functions
The XPathNavigator Abstract Class
Testing Nodes Against XPath Expressions
Selecting Nodes Using XPath Expressions
Precompiling XPath Expressions
Chapter 6: Validating XML
Defining a Grammar for XML Documents
Defining a Grammar Using a DTD
Defining a Grammar Using a Microsoft XDR Schema
Defining a Grammar Using an XSD Schema
Creating an XSD Schema in Visual Studio .NET
Creating an XSD Schema Using the XML Designer
Example of Creating an XSD Schema Using the XML Designer
Creating an XSD Schema from a Database
Example of Creating an XSD Schema from a Database Table
Creating an XSD Schema Using the XSD Generator
Creating an XSD Schema from an XML Document
Creating an XSD Schema from an XDR Schema
Creating an XSD Schema from an Assembly
Using the Schema Object Model
The Schema Object Model Class Hierarchy
Creating a Schema Using the Schema Object Model
Requirements for the Sample Application
Creating a New Schema
Creating Element Definitions
Creating a Complex Type
Specifying Detailed Information for an Element
Creating a Choice of Elements
Creating Attributes
Creating a Simple Type
Compiling the Schema
Writing the Schema Out
Building and Running the Sample Application
Sample Applications Online
Validating XML in the .NET Framework
Linking an XML Document to a DTD or Schema
Linking an XML Document to a DTD
Linking an XML Document to an XDR Schema
Linking an XML Document to an XSD Schema
Performing Validation
Creating a New Console Application
Creating a Validating Reader Object
Specifying the Type of Validation Required
Registering a Validation Event Handler Method
Reading and Validating the Document
Implementing the Validation Event Handler Method
Building and Running the Sample Application
Caching Schemas
Building and Running the Sample Application
Sample Applications Online
Summary
Chapter 7: Serializing XML
Serializing an Object as XML Data
Defining a Class for Use in Serialization
Creating Objects to be Serialized
Creating an XML Serializer
Serializing Objects
Examining Serialized Data in an XML Document
Deserializing XML Data into an Object
Defining a Class for Use in Deserialization
Creating an XML Serializer for a Particular Type
Deserializing Objects
Using a Deserialized Object
Dealing with Unexpected XML Content
Handling Unexpected Attributes
Handling Unexpected Elements
Handling General Unexpected Nodes
Serializing and Deserializing Complex Objects
Serializing and Deserializing Properties
Serializing and Deserializing Enumeration Values
Serializing and Deserializing Arrays
Serializing and Deserializing Composite Objects
Using Methods to Simplify Class Usage
Serializing and Deserializing with Inheritance
Fine-Tuning the Serialization Process
Defining Simple Formatting for Serialization
Formatting the XML Document Element
Defining Qualified Namespaces
Formatting XML Elements
Formatting XML Attributes
Formatting Text Content
Advanced Fine-Tuning Issues
Defining Ignorable Fields and Properties
Defining Enumeration Identifiers
Defining Polymorphic Arrays
Defining Nullable Object References
Using XSD Schemas with Serialization
Generating an XSD Schema from a Class
Example of Generating an XSD Schema from a Class
Generating a Class from an XSD Schema
Example of Generating a Class from an XSD Schema
Mapping XSD Types to Common Language Runtime Types
Serializing Object Graphs
Example of Serializing Object Graphs
Summary
Chapter 8: MSXML
What is MSXML?
Brief History of MSXML
MSXML Object Model
DOMDocument and FreeThreadedDOMDocument
Comparing Properties of DOMDocument and XmIDocument
Comparing Methods of DOMDocument and XmlDocument
Exclusive Features of DOMDocument
Exclusive Features of XmlDocument
XMLHTTP
Using XMLHTFP in VBScript
Comparing XMLH'FrP to Classes in the System. Net Namespace
XS LTe m plate
Using XSLTemplate in JavaScript
Comparing XSLTemplate to XsITransform
SAX
SAX vs. DOM
Comparing SAX to XmlReader
Using MSXML in .NET Code
Runtime Callable Wrappers
tlbimp.exe
What is Next for MSXML?
Summary
Chapter 9: Extending XmlReader and XmlWriter
Why Extend XmlReader and XmlWriter?
Why Use an XML Interface at All?
Why Use XmlReader/XMLWriter for the Interface?
Project Scope
Setting Up the Project
Creating a Runtime Callable Wrapper
Building XmlSimpleReader and XmlSimpleNode
Building XmlWord2OOOReader
Building XmlSimpleWriter
Building XmlWord2OOOWriter
Building XmlVisioReader
Building XmlVisioWriter
Summary
Chapter 10: ADO.NET
Role of XML in ADO.NET
ADO.NET vs. ADO
Any Similarities?
How Different?
Limitations with COM
Cursors
Recordset vs. ?
XML in ADO
Disconnected Data
Managed Data Providers
SQL Server .NET Data Provider
OLE DB .NET Data Provider
ODBC .NET Data Provider Beta 1
Common Model
DataSets
DataSet vs. ADO Recordset
DataSet vs. I DataReader
DataSet Collections
PropertyCollection
DataTableCollection
DataColumnCollection
DataRowCollection
DataRelationCollection
Reading and Writing XML with DataSets
WriteXml Method
XmlWriteMode
WriteXmlSchema Method
GetXml and GetXmlSchema Methods
ReadXml Method
XmlReadMode
Understanding the Inference Process
Loading Schema Information into the DataSet
ReadXmlSchema Method
InferXmlSchema Method
XML Namespaces
Prefix and Namespace Properties
Strongly Typed DataSets
XmlDataDocument
Synchronizing with a DataSet
When XmlDataDocument is the Data Source
When DataSet is the Data Source
Element and Row Conversions
GetElementFromRow Method
GetRowFromElement Method
Retrieving XML from SQL Server 2000
Using FOR XML
SQLXML Managed Classes
Summary
Chapter 11: ASP.NET
Introduction
What is ASP.NET?
Language-Neutral Execution
Compiled Execution
Event-Driven Processing and Web Forms
Server-Side Controls
Custom Web Controls
Error Handling and Tracing
Server-Side Caching
Configuration and Deployment
Compatibility with ASP
ASP.NET and XML
Web Forms and Web Controls
Web Form and Web Controls Namespaces
Web Forms in Action - User Feedback Web Form
Creating a New Web Project in Visual Studio .NET
Adding Controls to the Web Form and Setting their Properties
Examining the Markup Generated by Our Web Form
Writing Code for our Application
Common Web Controls
Using a DataGrid to Display an XML Document
Displaying XML from File
Displaying the Contents of the XMLDocument Object
Using the DataGrid to Display Complex XML Documents
Using the XML Control to Display an XML Document
Using the XML Control to Display Content from XML files
Using the XML Control with XmIDocument
Using the XML Control with a String of XML Data
ASP.NET Application Configuration
Location of web.config
Structure of web,config
Sections of web.config
Authentication
Authorization
CustomErrors
HttpHandlers
HttpModules
Pages
SessionState
Trace
appSettings
Using web.config Settings
Creating the Web Project and Modifying web.c0nfig
Developing the Iogin.aspx Page
Developing the default.aspx Page
Developing the myerror.aspx Page
Summary
Chapter I p. Case Study: Using ASP.NET and ADO.NET
DVD Rental System Design
Application Scope
The Technology Setup
Other Technical Requirements
Setting up the Environment
The Product Database
Adding a New Section to the Section Table
Editing a Row from the Section
Adding a New Item to the Item Table
Editing a Row from the Item Table
Displaying the Contents on the Browser
Admin
Client
The ASP,NET Code
The Admin Application
AddSection.aspx
Section,aspx
Addltem.aspx
Item.aspx
The Client Application
WebForml.aspx
Cart.aspx
Summary
Chapter 13: Web Services and SOAP
Web Services Overview
Market and Technological Forces
New Distributed Computing Model
.NET and Web Services
Building a Simple Web Service
Creating a Web Service in Visual Studio .NET
Writing Code for Our Simple Web Service
Testing Our Simple Web Service
Web Service Protocols
HTTP GET and HI-rP POST
SOAP
Using the SOAP Header
Controlling Header Direction
Requiring SOAP Headers
Handling SOAP Header Errors
Using Web Service Proxy Classes
Creating Our StockQuote Web Service
Creating a Web Service Client Application
Adding a Web Reference
Web Service Proxy Code
Using Web Service Proxies Asynchronously
Directory, Discovery, and Description
Web Service Directories - UDDI
Business Information - The businessEntity Structure
Service Information - The businessService Structure
Technical Service Descriptions - The bindingTemplate Structure
The UDDI APl
Web Services Description Language
WSDL Types
WSDL Messages
WSDL PortTypes
WSDL Bindings
WSDL Service Definition
State Management in Web Services
Using the Session Object
Using the Application Object
Transaction Support in ASP.NET Web Services
Deploying Web Services
Web Service Design Considerations
Message Design - Bigger Messages vs. More Traffic
Stateless Environment
Synchronous vs. Asynchronous Web Services
Loosely Connected Pieces of Functionality
Summary
Chapter 14: Case Study: Using Web Services
Application Background
Application Purpose
Project Description
Project Vision
Functional Requirements
Calendar Events Service
Tasks Service
Reminders Service
Sharing Tasks and Events
Technical Requirements
Usage Scenarios
User Classes
Web Service Design
Calendar Service Components
Calendar Web Service
Logging Module
Calendar Service Clients
Calendar Service Database Structure
Event Table
Task Table
Users Table
Group Table
UserGroup Table
Subscriber Table
UseLog Table
AutoSequence Table
Functional Specifications
Design Considerations
Web Service Methods
Calendar Service Application Clients
Calendar Service Implementation
Creating the ASP.NET Web Service
Building the GetEvents0 Method
Building the SaveEvent0 Method
Building the RemoveEvent0 Method
Building the GetReminders0 Method
Implementing Event and Task Sharing
Calendar Service Client Implementation
Building an ASP.NET Web Client
Creating the Main Calendar View
Adding the WroxCalendar Web Reference
Populating Events HTML
Building an Desktop Client
Creating the Event and Task Form
Populating the Event and Tasks Lists
Conclusion
Chapter 15: Remoting Overview
Remoting Basics
Object Activation
Server or Client Activation
Server-Activated Objects
Client-Activated Objects
Remoting Channels
Registering Channels
H~I-P Channel
TCP Channel
Summary
Chapter 16: C# Code Documentation
Advantages of XML Documentation in C#
Compilation of XML Documentation
Compiling at Command Line
Compiler Warnings
The/incremental Option
Compiling for Visual Studio .NET
Compiler-supplied Elements
Elements in XML Documentation
and
~c>
and
name Attribute of
and
Cref Attribute
type attribute
and
and
file Attribute
path Attribute
External File
Extensibility
Practical Use in the Middle-tier
Best Practices with Comments in the Middle-tier
Detailed Comments for Public Types and Members
Good Enough Comments for Non-Public Types and Members
Transformations
Sample Transformation Application
The XSLT Stylesheet
The Command Line Application
Other Considerations
Support for Documentation in VS.NET
Summary
Appendix A: System.Xml
Overview of System.Xml Classes
The XmlException Class
The XmlConvert Class
The Xmllmplementation Class
The XmlNamedNodeMap Class
The XmlAttributeCollection Class
The XmlNamespaceManager Class
The XmlNameTable Class
The XmlNode Class
The XmlAttribute Class
The XmlDocument Class
The XmlDataDocument Class
The XmlDocumentFragment Class
The XmlEntity Class
The XmlLinkedNode Class
The XmlCharacterData Class
The XmlCDataSection Class
The XmlComment Class
The XmlSignificantWhitespace Class
The XmlText Class
The XmlWhitespace Class
The XmlDeclaration Class
The XmlDocumentType Class
The XmlElement Class
The XmlEntityReference Class
The XmlProcessinglnstruction Class
The XmlNotation Class
The XmlNodeList Class
The XmlParserContext Class
The XmIQualifiedName Class
The XmlReader Class
The XmlNodeReader Class
The XmlTextReader Class
The XmlValidatingReader Class
The XmlResolver Class
The XmlUrlResolver Class
The XmlWriter Class
The XmlTextWriter Class
Appendix B: System.XmI.Xsl and System.XmI.XPath
System,XmI.Xsl Namespace
Overview of System.Xml.Xsl Classes
The XsltArgumentList Class
The XsltContext Class
The XsltException Class
The XsitCompileException Class
The XslTransform Class
The System.Xml,XPath Namespace
Overview of System.Xml.XPath Classes
The XPathDocument Class
The XPathException Class
The XPathExpression Class
The XPathNavigator Class
The XPathNodelterator Class
Appendix C: .NET Glossary
Appendix D: Resources
Web Sites
Books
Technical Articles and Reports
Specifications
Other Web Sites
Index
This book will cover the intersection between two great technologies: .NET and XML.
XML has been a hot topic for some time. The massive industry acceptance of this W3C Recommendation,which allows data communication and information storage in a platform-agnostic manner, has been astounding. XML is seen and used everywhere - from the display of data on various browsers using the transformation language XSLT, to the transport of messages between Web Services using SOAP.
.NET is Microsoft's revolutionary and much vaunted new vision. It allows programming of applications in a language-independent manner, the sharing of code between languages, self-describing classes, andself-documenting program code to name but a few of its capabilities..NET has been specifically designed with Web Services and ease of development in mind.
To achieve this exciting new programming environment, Microsoft has made extensive use of XML. In fact no other technology is so tightly bound with .NET as XML. It is used as the universal data format for everything from configuration files to metadata, RPC, and object serialization. All the XML capabilities that were formerly available to the programmer through the MSXML parser are now encapsulated in the system. Xml namespace of classes, together with added performance, and new and exciting functionality. Connected to this is the new support for XML that ADO.NET has. For example, the programmer now has the ability to access and update data in both hierarchical (XML) and relational (database) form at the same time.
Who Is This Book For?
This book is aimed at intermediate or experienced programmers who have started on their journey towards .NET development and who are already familiar with XML.
While we do introduce the reader to many .NET concepts in Chapter 1, this book is not aimed as a first port of call for the developer looking at .NET, since there are already many books and articles covering this area. Instead we cut straight to the heart of using XML within the .NET Framework. To get the most out of the book, you will have some basic knowledge of, or be learning, either C# or VB .NET. Examples will be given in both languages either within the text or in the code download, wherever possible.
In a similar vein, there are many books and articles that cover the XML technologies that you'll need to use this book. We assume a general knowledge of XML, Namespaces, and XSLT, and a basic knowledge of XML Schemas.
For further inJbrmation on Cqf , VB .NET, and XML technologies, check the resources listed in Appendix D.
What Does This Book Cover?
This book looks at how the .NET framework uses XML, and how the developer can utilize the full power of XML within the .NET Framework, and has two main aims:
To give the reader an understanding of the classes within the .NET Framework library that can be used to manipulate XML. For example, reading and writing, validation, and DOM manipulation.
To explain how XML is used by the .NET Framework itself. This includes XML-based configuration files, the use of XML in Remoting and Web Services, and the integration of
XML within ADO.NET that allows us extra functionality when dealing with databases.
The following is a more detailed breakdown of the chapters and appendices:
Chapters
1: .NET Framework Overview
In Chapter i we aim to give the reader an overview or reminder (depending on their level of existing knowledge) of what the .NET Framework is all about.
We'll look into the .NET Framework, the Common Language Runtime and Common Language Specification. We ask, "What is an Assembly?" and go on to talk about Application Domains and Framework Security. Later on we look at Application Deployment and the .NET languages, C# and VB .NET, before discussing ASP.NET and the various controls available: HTML, Web, Validation, and Mobile controls. Finally we look at the new ADO.NET for database access.
2: XML in the .NET Framework
In Chapter 2, we take a brisk walk through all the XML integration features in the .NET Framework, which we'll look at in more detail throughout the rest of the book. Microsoft has introduced several new applications of XML in .NET and has also done some innovative work to improve the core XML AP1. We start with a discussion on the use of XML in configuration files, and look at Startup, Runtime, and Remoting settings. We see how XML, in conjunction with some new ADO.NET features, fixes some of the problems that ADO has. We look at ASP.NET and examine streaming and DOM-based XML classes, before introducing the System. x_mi namespace of classes, including the abstract classes XmlReader, and XmlWriter. We take a quick look at DOM, XPath,
XSLT, and MSXML in .NET, along with the new C4f XML code documentation feature. Finally, we discuss the Framework's support for producing and consuming XML documents.
3: Reading and Writing XML
Chapter 3 starts a section of chapters (3 through 7) that look at the functionality contained within the System. Xml namespace in more detail.
In particular, here we look at the fast, forward-only mechanisms provided by the .NET Framework for reading and writing XML documents, namely the XmlReader and xmlwr~ ter abstract classes. We explore the XmlTextReader and XmlTextWriter classes, which are derived from these abstract classes. We go on to discuss node order, whitespace, entity and namespace handling, and other namespace support.
4: DOM Navigation of XML
In Chapter 4 we look at the DOM functionality in the .NET framework provided within the System. Xml namespace of classes. We look at opening documents from URLs, files, or strings in memory, and searching and accessing the contents of these documents, before serializing them back out to XML strings. We also take a look at the differences between the XralDocument object and the XmlReader and XmlWriter abstract classes, and where using each is more appropriate. Finally, we create a class derived from the XmlDocument class, to show how easy it is to add functionality to the classes in the .NET framework.
5: XSL Transformations of XML
The .NET framework provides robust support for XSLT and XPath processing. In Chapter 5 we look at the technologies used for XSL transformations in the .NET Framework, namely the Sys t em. Xral. Xs 1 and Sys tern. Xml. xPath namespaces, as well as the xs 1Trans form class. The .NET Framework fully supports the XSLT and XPath specifications as defined by the W3C, but also provides many helpful extensions to these specifications, which enhance the usability of stylesheets within .NET applications. We look at using embedded scripting with for transforming XML documents and how to extend stylesheets with extension objects. We also discuss XPathDocument objects. Towards the end of the chapter we look at tuning XSL transformations for performance, smart pipelining, and finally other XPath functions.
6: Validating XML
In Chapter 6 we take look at the different options for the XML validation grammars: DTDs, XDR schemas, and XSD schemas. We go on to look at all the ways we can create an XSD Schema in Visual Studio .NET: using the XML Designer, from a Database, using the XSD Generator, from an XML Document, from an XDR Schema, or from an Assembly. We discuss the Schema Object and see how we can link XML documents to DTDs, XDR schemas, and XSD schemas, and how to then perform validation using the XralValidatingReader object from the system. Xml namespace. We look at using XmlSchemaCollection to keep a cache of schemas in memory, to optimize performance, and also deal with unqualified/namespace-qnalified content in XML documents.
7: Serializing XML
In Chapter 7 we look at serializing objects as XML data using the XmlSerializer class from the System. Xml. serialization namespace. More specifically we create serializers, and then serialize and deserialize complex objects, properties, enumeration values, arrays, and composite objects. We look at serializing and deserializing with inheritance, followed by formatting XML elements, XML attributes, and text content. Towards the end of the chapter we look at using XSD schemas with serialization and mapping XSD types to Common Language Runtime types. Finally we investigate serializing complex object graphs.
8: MSXML
By Chapter 8 we will already have explored most of the classes provided within the System. Xml namespace of the .NET Framework library. So, in Chapter 8, we explore the pre-.NET Microsoft XML API provided in MSXML. We look at this from various standpoints before discussing how some MSXML objects compare to related objects in .NET. We look at MSXML's DOMDocument and FreeThreadedDOMDocument, and then compare the methods of MSXML's DOMDocument to .NET's XmlDocument. We demonstrate how to use the classes in the .NET System. Net namespace that perform similarly to the MSXML XMLHTTP object. Similarly we compare MSXML's XSLTemplate (using it inJavaScript), to .NET's XslTransform. We compare SAX (which, although available in MSXML, is not directly available within .NET) to DOM and XmlReader. Finally we cover using Runtime Callable Wrappers for when we need to use MSXML from within .NET code.
9: Extending XmlReader and XmlWriter
In Chapter 9 we look at extending the XmlReader and xm!Writer abstract classes we first looked at in detail in Chapter 3, to communicate the grammar specified in a schema. More specifically, we use the extended classes and Runtime Callable Wrappers to enable an application to translate between an XML document, a Microsoft Visio diagram, and a table in a Microsoft Word document.
10: ADO. NET
In Chapter 10 we start to move away from the realm of the System. xml namespace of classes, to explore the broader picture of how XML is used in .NET. Chapter 10 looks at the role of XML in ADO.NET, and compares ADO.NET with ADO. We cover the capabilities of the new DataSet class, including reading and writing XML, and programmatically accessing or changing its XML representation. We highlight how to synchronize DataSets with XmlDataDocuments (derived from the XmlDocument class), and why we would do so. We also cover the advantages of strongly typed DataSets. Finally we take a glimpse at how to access some of the XML features available with SQL Server 2000.
11: ASP. NET
In Chapter 11 we examine what ASP.NET is, its compatibility with ASP, and how ASP.NET and XML are related to one another. We look at Server-side and Web controls, as well as error handling and tracing. We see how we can use the XML control to display XML from either a file or an XralDocument object, and use the DataGrid control to display complex XML documents. Other topics we look at are server-side caching, authentication, authorization, configuration, and deployment. We study the location, structure, and different sections of the XML configuration document web. config, before finally looking at custom errors, HTTP handlers, and HTTP modules.
12: Case Study: Using ASP. NET and ADO. NET
In this case study we create an online DVD rental system, and demonstrate how the application can be implemented without large chunks of complicated code. In particular, we look at features of ASP.NET and server-side controls, how to open database connections using ADO.NET, reading data in XML format, and how ADO.NET has a built-in support for XML. We look at the design and other technical requirements, before seeing how we can add new sections and edit rows, and then using server-side XSL, make the application browser-independent.
13: Web Services and SOAP
In Chapter 13 we explore the new world of .NET Web Services, and how they use XML technologies. We show how to build a simple Web Service in Visual Studio .NET, and discuss the protocols used by Web Services, namely HTTP GET/POST and SOAP. As an example we create our own "Stock Quote" Web Service. We look at proxy code, Web Service directories, the businessEntity and businessService structures, the XML-based Web Service Description Language (WSDL), and using the Session and Application objects. Finally we look at deployment and design considerations, and the difference between synchronous and asynchronous Web Services.
14: Case Study: Using Web Services
In this Case Study we create a sample Web Service providing calendar features. We walk through the Web Service's conceptual design including use-cases and functional requirements. We then create and discus a simple database to support our calendar application. The focus of this chapter is on coding the Web Service and its constituent methods. Finally we will build a simple ASP.NET client application to consume the Web Service.
15: Remoting Overview
In Chapter 15 we discuss the remoting basics, followed by object activation on both the client and the server. We cover how remote objects are instantiated and activated and our options for controlling that behavior, as well as discussing how .NET accomplishes remoting using local proxies that represent remote objects. We cover the basics of creating a .NET remoting application including building simple client and server applications, before looking at the obi Ref class, lifetime leases, remoting and registering channels, and the HTTP and TCP channels.
16: C# Code Documentation
In this final chapter, Chapter 16, we look at the advantages of XML code documentation in C# We look at how to compile commented code at the command line with the /doc: fi 2 ename option, as well as the compiler warnings and the /incremental option. We then move on to look at compiling commented C#code in Visual Studio .NET, and an in-depth look at the various compiler-supplied elements and attributes. The next part of the chapter looks at making practical use of comments, the best practices for them, and comments for public and non-public types and members. We then look at transformations to turn our XML into a more readable help file, followed by a sample transformation application and the associated XSLT stylesheet. We end by looking at other considerations such as how Visual Studio .NET provides us with web-based documentation based on our use of the XML documentation tags.
Appendices
A: System. Xml
In Appendix A we look at the system. Xml namespace, and take an overview of System. Xral classes. This namespace, the overall namespace for the XML classes, deals with the functionality of accessing,
navigating, and maintaining XML data.
B: System.XmLXsl and System.XmLXPath
In Appendix B we look at the commonly used namespaces System. Xml. Xsl and System. Xml. XPath. These namespaces deal with XSL transformations and navigation of XML documents, respectively.
C: .NET Glossary
Appendix C is a useful reference explaining the meaning of many of the .NET terms.
D: Resources Appendix D is a helpful list of the URLs and titles referenced throughout this book, for further reading, and downloading products and code.
What You Need to Use This Book
To run the examples used in this book, you will need to install the .NET Framework. You can order a copy of the Framework on CD-ROM, or download it from the Microsoft web site. At the time of writing, the .NET Framework was at Beta 2 version, but any amendments will be posted on the Wrox web site http://www, wrox. com/.
Most code can be written using you favorite text editor and compiled from the command line using the tools provided with the .NET Framework. However, you may also want to use Visual Studio .NET to create and compile your code: this is currently in Beta 2 and can be downloaded from http://msdn.microsoft.com/vstudio/nextgen/beta.asp.
Where chapters require other software, it is mentioned explicitly. In particular:
Some of the code in Chapters 10, 12, and 14 needs SQL Server 2000. A 120-day trial version for this software can be downloaded from http://www.microsoft.com/sql/.
Chapter 9 Customizing Abstract Classes uses Microsoft Word and Microsoft Visio. However, the example will work with just Microsoft Word, but with more limited functionality.
The code included in this book can be downloaded from http://www.wrox.com/. More details are given in the Customer Support section below.
Conventions
To help you get the most from the text and keep track of what's happening, we've used a number of conventions throughout the book.
For instance:
These boxes hold important, not-to-be forgotten information, which is directly relevant to the surrounding text. In comparison, this style is used for asides to the current discussion.
As for styles in the text:
When we introduce important words, we highlight them
We show keyboard strokes like this: Ctrl-Alt-Delete
We show filenames, and code within the text like so: sample, cs
Text on user interfaces is shown as: File I Save
URLs are shown in a similar font, as so: http://www.wrox.com/
Namespace URIs, however, are shown like this: http: //www.w3. org/2001/XMLSchema
When referring to chapter sections or titles, we italicize it, as so: Introduction
We present code in two different ways. Code that is new or important is shown like this: in 0ur code exalnples, the code foreground style shows new, importanti and pertinent code
Code that is an aside, or has been seen before is shown as so:
Code background shows code that's less important in the present context, or that has been seen before.
In addition, when something is to be typed at a command line interface (for example, a DOS/Commar prompt), then we use the following style to show what is typed:
> csc.exe /t:exe /out:example. CS.exe example. CS
Customer Support
We always value hearing from our readers, and we want to know what you think about this book: whal you liked, what you didn't like, and what you think we can do better next time. You can send us your comments, either by returning the reply card in the back of the book, or by e-mail to feedback@wrox.com. Please be sure to mention the book title in your message.
How to Download the Sample Code for the Book
When you visit the Wrox site, http://www.wrox.com/, simply locate the title through our Search facilit'or by using one of the title lists. Click on Download in the Code column, or on Download Code on the book's detail page.
The files that are available for download from our site have been archived using WinZip. When you have saved the attachments to a folder on your hard-drive, you need to extract the files using a de-compression program such as WinZip or PKUnzip. When you extract the files, the code is usually extracted into chapter folders. When you start the extraction process, ensure your software (WinZip,PKUnzip, etc.) is set to use folder names.
Errata
We've made every effort to make sure that there are no errors in the text or in the code. However, no one is perfect and mistakes do occur. If you find an error in one of our books, like a spelling mistake or a faulty piece of code, we would be very grateful for feedback. By sending in errata you may save another reader hours of frustration, and of course, you will be helping us provide even higher quality information. Simply e-mail the information to support@wrox.com. Your information will be checked and, if correct, posted to the errata page for that title, or used in subsequent editions of the book.
To find errata on the web site, go to http://www.wrox.com/, and simply locate the title through our Advanced Search or title list. Click on the Book Errata link, which is below the cover graphic on the book's detail page.
E-mail Support
If you wish to directly query a problem in the book with an expert who knows the book in detail then e-mail support@wrox.com, with the title of the book and the last four numbers of the ISBN in the subject field of the e-mail. A typical e-mail should include the following things:
The title of the book, last four digits of the ISBN, and page number of the problem in the Subject field.
Your name, contact information, and the problem in the body of the message.
We won't send you junk mail. We need the details to save your time and ours. When you send an e-mail message, it will go through the following chain of support:
Customer Support - Your message is delivered to our customer support staff, who are the first people to read it. They have files on most frequently asked questions and will answer anything general about the book or the web site immediately.
Editorial - Deeper queries are forwarded to the technical editor responsible for that book.
They have experience with the programming language or particular product, and are able to answer detailed technical questions on the subject.
The Authors - Finally, in the unlikely event that the editor cannot answer your problem, they will forward the request to the author. We do try to protect the author from any distractions to their writing; however, we are quite happy to forward specific requests to them. All Wrox authors help with the support on their books. They will e-mail the customer and the editor with their response, and again all readers should benefit.
The Wrox Support process can only offer support to issues that are directly pertinent to the content of our published title. Support for questions that fall outside the scope of normal book support is provided via the community lists of our http://p2p.wrox.com/forum.
p2p.wrox.com
For author and peer discussion join the P2P mailing lists. Our unique system provides programmer to programmerTM contact on mailing lists, forums, and newsgroups, all in addition to our one-to-one e-mail support system. If you post a query to P2P, you can be confident that it is being examined by the many
Wrox authors and other industry experts who are present on our mailing lists. At p2p.wrox.com you will find a large number of different lists that will help you, not only while you read this book, but also as you develop your own applications. Particularly appropriate to this book are the xml, ado_dotnet, aspx, dotnet_webservices, c_sharp, and vb_dotnet lists.
To subscribe to a mailing list just follow these steps:
1. Go to http://p2p.wrox.com/.
2. Choose the appropriate category from the left menu bar.
3. Click on the mailing list you wish to join.
4. Follow the instructions to subscribe and fill in your e-mail address and password.
5, Reply to the confirmation e-mail you receive.
6. Use the subscription manager to join more lists and set your e-mail preferences.
Why this System Offers the Best Support
When you join a mailing list you can choose to receive individual e-mails as they are posted, to receive a daily digest of messages, or to receive no e-mail at all and to just read/reply via the web site. You can also search our online archives. Junk and spam mails are deleted, so that only relevant content is sent to you. Queries about joining or leaving lists, and any other general queries, should be sent to list support@p2p.wrox. com.