Web services are perhaps the most important feature of .NET development .They take componentization to a new level by allowing method calls to be made over the Internet or over an intranet using standard protocols such as HTTP and SOAP.this means that the calling application needs to know nothing about the internal implementation of the servicebuilt on Linux using Java.
The .NET Framework provides two ways to build web services –ASP.NET and .NET Remoting .Unlike most books on web services,this book covers both of these technologies in depth ..NET Remoting web services require a little extra effort to build,but they offer us greater flexibility.They allow us to use different encoding and ch\annels,and they can be hosted in any application,not just IIS.
Introduction
What Are Web Services?
What Does This Book Cover?
Who Is This Book For?
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
Section One - Getting Started
Chapter 1: What is a Web Service?
History of Distributed Computing
The Client-Server Model
Component Technology
Into the Present
Web Services
Benefits of Using Web Services
Standards for Web Services
Web Services Architecture
Exposing Web Services
Consuming Web Services
The Future of Web Services
Programmable Web
.NET My Services
Services
Issues
The Future of .NET MY Services
Summary
Chapter 2: Web Service Protocols
SOAP
Format
Data Types and SOAP Serialization
SOAP Over HTTP
WSDL
Format
Types
Message
portType
Binding
Service
SOAP Messages
Client Proxies
DISCO
Format
UDDI
Summary
Chapter 3: Web Services and the .NET Framework
The SOAP Toolkit
Overview
Exposing Web Services
Consuming Web Services
Exposing a COM Object with the SOAP Toolkit
When to Use the SOAP Toolkit
Summary of the SOAP Toolkit
ASP.NET
Exposing Web Services
Namespaces
Consuming Web Services
.NET Remoting
When to Use .NET Remoting
ATL Server
When to Use ATL Server
Summary
Section Two - ASP.NET Web Services
Chapter 4: Building an ASP.NET Web Service
Overview of ASP.NET Web Services
Web Service Protocols
SOAP
The SOAP Protocol Specification
Simple SOAP Request Example
HTTP
System .Web .Services. Protocols
The WebClientProtocol Class
Web Service Architecture
Quick Reference for Architecture Components
Discovery Files
The Service Description
Viewing a WSDL Document
The wsdl.exe Utility
How .NET Uses WSDL Documents
Creating a Credit Card Validation Web Service
ASP.NET Web Service Data Types
Creating a Web Service Without the Visual Studio .NET IDE
Creating an IlS Virtual Directory
The WebService AtLribute
The WebMethod Attribute
Creating a Web Service with Visual Studio .NET
Testing Web Services
Testing the Service from a Browser
Debugging with the IDE
Examining and Modifying the SOAP Response
Parameter Encoding
SOAP Body Formatting
Document Encoding Style
RPC Encoding Style
State Management in Web Services
Accessing and Using the Application Object
Accessing and Using the Session Object
Deploying and Configuring Web Services
The Web. Config File
Summary
Chapter 5: Consuming ASP.NET Web Services
How do Clients Communicate with Web Services?
Calling a Web Service with H'i-rP
Calling a Web Service with SOAP
Discovering ASP.NET Web Services
UDDI
The disco.exe Tool
Discovering Web Services using Visual Studio .NET
Viewing and Using the WSDL Document
Creating the Proxy
Using wsdl.exe
Using csc to Compile the Proxy Class
Using the Compiled Proxy DLL Assembly
Details of the Generated Proxy Class
Automatic Proxy Creation Using Visual Studio .NET
Synchronous vs. Asynchronous Calls
The .NET Framework Design Pattern
Creating a Web Service Client
Building a Sample Client in C#
Using the Web Service in Code
Debugging the Consumer
Setting up ASP.NET Debugging
Stepping into the Web Service
Inside the Web Service Call
Things to Keep in Mind
Summary
Section Three- .NET Remoting
Chapter 6: .NET Remoting Architecture
What is .NET Remoting?
Web Services Anywhere
CLR Object Remoting
.NET Remoting Fundamentals
Remote Object
Server
Server Configuration File
Machine.con fig
Starting the Channel
Client
Client Configuration File
Client Application
Running the Server and the Client
More ,NET Remoting
System. Runtime. Remoting Namespace
Remote Objects
Well-Known Objects
Client-Activated Objects
Lease-Based Lifetime
Remote Object Types Summary
Activation
RemotingServices.Connect
Error Messages
Proxy
Messages
Marshaling
ObjRef
Passing Objects
Marshal-By-Value
Marshal-By-Reference
Client Example
Sending MBR Objects to the Server
Tracking Services
Tracking Handler
Register Tracking Handier
Running the Program
Asynchronous Remoting
Calling Local Methods Asynchronously
Calling Remote Methods Asynchronously
Callbacks with Delegates
One Way
Call Contexts
Summary
Chapter 7: Web Services Anywhere
Application Scenarios
XML Web Services
Web Services with Binary Formatters
Peer-to-Peer Web Services
Hosting Servers
Hosting Web Services in ASP.NET
Create a Virtual Web Directory
Remote Object Class
Server Configuration File
Client
Restrictions
Using ASP,NET Features
Channels
IChannel Interface
IChannelReceiver Interface
IChannelSender Interface
TCP Channel
HTFP Channel
Formatters
Serialization
Binary Formatter
SOAP Formatter
Comparing Formatter Results
Binary Format
SOAP Format
Comparing DataSets with Binary and SOAP Formatters
Channels and Formatters
Formatter Sink Provider
Assigning Sink Providers Programmatically
Predefined Sink Providers
Using Configuration Files for Sink Providers
Summary
Chapter 8: Building a Web Service with .NET Remoting
Introducing Our Pizza Delivery Example
Use Case Diagram
Deployment
Assemblies
Classes
Ordering a Pizza
Data Services
Database Diagram
Stored Procedures
Data Access Component
PizzaOrder Assembly
PizzaOrderDetail
PizzaOrder
Pizza Order Web Service
MarshalByRefObject
Error Handling
Remote Methods
Test Server
Configuration File
PizzaDeliveryService Web Service
Deliver Pizzas - Sequence
PizzaDeliveryService - Remote Object Class
Two Channels for Two Remote Objects
Creating an Application Domain
Configuration File
Supporting Events
Order a Pizza Sequence with Events
Delegates and Events for PizzaDeliveryService
Invoking the Event
Changing the PizzaOrderService Implementation
Assigning the Deregate
Windows Service
Summary
Chapter 9: Building a .NET Remoting Client
Web Services
ASP.NET Client
Web.Config
Remoting Services and WSDL
Soapsuds Utility
Creating a Proxy Using soapsuds
Creating an Assembly Using Soapsuds
Filling the DataGrid
Page_Load Event
DataGrid Templates
Submit Handler
Windows Forms Client
User Interface
Client Channel Configuration
Implementing the Windows Event Handlers
Process the Selected Order
Running the Client Application
Adding Event Handling
Creating a Sink Class
Registering a Sink Object
Summary
Section Four - Advanced Topics
Chapter 10: Universal Description, Discovery, and Integration (UDDI)
What is UDDI?
Web Services Discovery Mechanism
What are DISCO Files?
LIDDI Building Blocks
Accessing UDDI on the Web
Accessing UDDI Programmatically
The UDDI Data Structures
Storing Business Information
Storing Service information
Technology Models
The Microsoft UDDI SDK
Using the Send Tool
Using the SDK With C#
Making an Inquiry
Finding a Business
Finding a service
Publishing to UDDI
UDDI Security
Saving Information to UDDI
Removing Information from UDDI
Summary
Chapter 11: .NET Security and Cryptography
Web Service Security
,NET Security Overview
.NET Security Framework APl
Permission Objects
Code Access Security
Role-Based Security
Security Tools
Web Service Security Layers
IP Security
TCP Layer Security
Application Layer Security
Cryptography Basics
Hash Algorithms
Cryptographic Hash Algorithms
X.509 Certificates
Secure Sockets Layer
Encrypting your Web Service Data
Credit Card Validation Example
Enhancing the Credit Card Validation Sample
Summary
Chapter 12: Web Services es Application Plug-ins
Designing the GUI
Drawing our Form
Writing the Code
Starting Up
Populating the DataSet
Loading the Form Controls with Data
Handling Form Events
Adding Data to the Database
Data Access Methods
Versioning and Distribution Concerns
Creating a Class Library from our WinForm Code
Making the Web Service
Building the Web Service
Building a Windows Client
Summary
Section Five - Case Studies
Case Study1 - ASP.NET
Overview of the Application
Business Processes
Limitations
Prerequisites
Architecture of the System
Implementation
The Database Design
WroxOnline Database Design
AirlineServiceProvider Database Design
Implementing the Web Service
Creating the Proxy Class Library
Using the WSDL Utility
Using Visual Studio .NET and the Add Web Reference Option
Implementation of the .NET Component
Windows Service Applications
Implementing the Stock Polling Service
Implementing the WroxOnline Web Application
A Look at User Controls
Enabling Form-based Authentication
The Login Page
The Registration Page
The Search for Flights Pages
The Book Tickets Page
The News and Deals Display Page
Exception Handling
Putting It All Together
Summary
Case Study 2: P2P .NET Remoting
Aims and Design Goals
Planning the Development
Identifying the Components
Abstracting the Design
Message Design
Iteration I - A Boilerplate Channel Sink
Iteration 2 - Serialization and SOAP Boxing
Iteration 3 - Cryptographic Modeling
Eliminating the Certificate Authority
Signing and Encrypting Data
Iteration 4 - Plugging Cryptography into the Channel Sink
Consolidating the Cryptography Classes
Mapping Public Keys to Web Services
Managing the Key Store Manually
Putting it Together - A Security Channel Sink
Final Integration - Walking the Talk
Analyzing the Stack Trace
To-Do List
Application Scenarios
Characteristics of Peer to Peer Applications
Peer-to-Peer instant Messaging
Anonymous Payment Systems
P2P invoice and Ordering System
Supply Chain Management
Summary
Section Six - Appendix
Appendix A: .NET Remoting Object Model
Context-Agile Objects
Context-Agile Marshal-by-Value Objects
AppDomain-Bound Context-Agile MBR Objects
Context-Bound Marshal-by-Reference Objects
.NET Remoting Building Blocks
Remoting Hosting Options
Remoting Transport Channels
Remoting Message Serialization and Deserialization Formatters
Remoting Lifetime Management with Leases
Remoting Activation Policies
.NET Remoting Framework Classes
Remoting Configuration File Format Reference
Server-Side Registration
Client-Side Registration
Index
What Are Web Services?
Web services are the latest thing in application development, and have attracted the interest of developers working on all platforms. The fundamental concept is simple - web services allow us to make Remote Procedure Calls (RPCs) against an object over the Internet or a network. Web services aren't the first technology to allow us to do this, but they differ from previous technologies in that their use of platform-neutral standards such as HTTP and XML allows us to hide the implementation details entirely from the client. The client needs to know the URL of the service, and the data types used for the method calls, but doesn't need to know whether the service was built in Java and is running on Linux, or is an ASP.NET web service running on Windows.
Microsoft has enthusiastically taken up support for web services in the .NET Framework. In particular, it has provided a number of tools (not least Visual Studio .NET) that make building and accessing web services extremely easy. This book looks at the different ways that we can build web services using C# and the .NET Framework, and at the tools, technologies, and protocols that we will need to work with if we're to take advantage of this vital development.
What Does This Book Cover?
The .NET Framework provides two ways to build web services: ASP.NET and .NET Remoting. In this book, we will look at both of these methods in detail, providing plenty of example services to show how these will integrate into real applications, and to provide ideas about potential uses for this vital new technology.
We start in Chapter 1 by looking at what web services are, why they are needed, and how they developed. We also look at some of the benefits that can be gained by using web services, and take ~f high-level overview of the architecture of a web service.
Chapter 2 looks at the standards and protocols that web services are based on - SOAP and WSDL. It is these standards that allow web services to hide their implementation details, and provide the cross- platform interoperability that is one of the key advantages of web services.
In Chapter 3, we start to delve into the specifics of Microsoft's implementations of web services. The Microsoft world provides four ways to build web services (apart from manually creating the SOAP and WSDL files!): ASP.NET and .NET Remoting (which we cover in depth in this book), the VB SOAP Toolkit for exposing COM components as web services, and ATL Server (which provides an easy way to build ISAPI filters, including web services, in unmanaged C++).
We now move on to the core of the book - the sections that will look, in detail, at building web services and web service clients using the tools provided by the .NET Framework. Chapter 4 demonstrates building an ASP.NET web service. We see how to create, test, debug, and deploy an ASP.NET web service using the example of a credit card validation service.
Now that we've got a web service, we'll need to access it, so Chapter S discusses how to build a client for our new service. There are two ways to do this automatically - using the command-line tool wadi. exe, and using Visual Studio .NET. This chapter looks at both of these methods of generating ASP. NET web service clients.
The next four chapters deal with .NET Remoting web services. This section starts with an overview of Remoting and the .NET Remoting architecture in Chapter 6. Here we introduce the concepts and classes used by the Remoting infrastructure.
Next, in Chapter 7, we look at building web services with .NET Remoting and Web Services Anywhere, which is Microsoft's name for web services that use Remoting..NET Remoting allows us to host our web services in any application - not only IIS- and to use any channel (both a TCP and an HTTP channel are provided), and any format (SOAP and binary formatters are provided).
Now that the concepts of Remoting and Web Services Anywhere have been introduced, we build an example Remoting web service in Chapter ii. This chapter uses the example of a pizza delivery company, and uses both the HTTP and TCP channels.
Again, now that we've got a web service, we'll need to build a client application to access it. Chapter 9 does just this, using the soapsuds, exe utility to create a proxy for the web service, and building web and Windows clients for our service.
The usefulness of web services is obviously limited if we need to know their URLs before they can be accessed. Chapter 10 looks at Universal Description, Discovery, and Integration (UDDI), which provides a means for us to publish the URLs of our web services and descriptions of their functionality. This allows potential users to find them without having to know their URL in advance.
Chapter 11 looks at an important but little-documented topic - securing web services using the .NET cryptography classes. To demonstrate this, we use a Remoting web service and build a custom channel sink where we apply the encryption/decryption. This concept is developed further in Case Study 2.
Chapter 12 demonstrates an interesting possibility - using a web service to deliver a ~rindows forms assembly, which can then be instantiated on the client. We use the example of a time~heet application which can be downloaded from our web service and saved locally or run directly. This provides an interesting solution to distribution and versioning problems with desktop applications. We also allow the application's data to be saved to the client, so the application can be run even if no network connection is available.
Finally, to demonstrate some of the possibilities of web services, we look at two Case Studies. The first is a flight reservation system built around an ASP.NET web service, and demonstrates how a web service can be integrated into a large web application. The second uses .NET Remoting, and demonstrates how we can build a custom channel sink to implement a cryptography layer that we can plug in to any Remoting web service.
Who Is This Book For?
This book is aimed at experienced developers, who already have some experience of developing or experimenting within the .NET Framework with CS:. We also assume some familiarity with ASP.NET and web programming.
What You Need to Use This Book
To run the examples in this book you need to have the following:
Windows 2000 or Windows XP with lis 5 or later
The .NET Framework SDK Beta 2 or later. The code in this book will not work with .NET Beta 1. Wherever possible, the code has been tested with the Release Candidate.
The complete sourcecode for the examples is available for download from our web site at http://www.wrox.com/Books/Book_Details.asp?isbn= 1861004397.
Conventions
We've used a number of different styles of text and layout in this book to help differentiate between the different kinds of information. Here are examples of the styles we used and an explanation of what they mean.
Code has several fonts. If it's a word that we're talking about in the text - for example, when discussing a for (...) loop, it's in this font. If it's a block of code that can be typed as a program and run, then it's also in a gray box:
for (int i = O; i < 10; i++)
{
Console.WriteLine (i);
}
Sometimes we'll see code in a mixture of styles, like this-
for (iht i = 0; i < 10; i++)
{
Console .Write ( "The next number is: );
Console. WriteLine ( i );
}
In cases like this, the code with a white background is code we are already familiar with; the lir highlighted in gray is a new addition to the code since we last looked at it.
Advice, hints, and background information comes in this type of font.
Important pieces of information come in boxes like this.
Bullets appear indented, with each new bullet marked as follows:
Important Words are in a bold type font
Words that appear on the screen, or in menus like the File or Window, are in a similar font to the one you would see on a Windows desktop
Keys that you press on the keyboard like Ctrl and Enter, are in italics
Customer Support
We always value hearing from our readers, and we want to know what you think about this book: what 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 facility 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 number of different lists that will help you, not only while you read this book, but also as you develop your own applications.
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
You can choose to join the mailing lists or you can receive them as a weekly digest. If you don't have the time, or facility, to receive the mailing list, then you can search our online archives. Junk and spam mails are deleted, and your own e-mail address is protected by the unique Lyris system. Queries about joining or leaving lists, and any other general queries about lists, should be sent to listsupport @ p2p.wrox.com.