Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

C# ПІДРУЧНИКИ / c# / MS Press - Msdn Training Programming Net Framework With C#

.pdf
Скачиваний:
175
Добавлен:
12.02.2016
Размер:
16.87 Mб
Скачать

Module 13: Remoting and XML Web Services

iii

 

 

 

Instructor Notes

Presentation:

120 Minutes

Lab:

105 Minutes

After completing this module, students will be able to:

!Write and configure distributed applications that use .NET Remoting.

!Create an XML Web service by using Microsoft® Visual Studio® .NET and ASP.NET.

!Consume an XML Web service by using the Web Services Description Language tool (Wsdl.exe).

Materials and Preparation

This section provides the materials and preparation tasks that you need to teach this module.

Required Materials

To teach this module, you need the Microsoft PowerPoint® file 2349B_13.ppt.

Preparation Tasks

To prepare for this module, you should:

!Read all of the materials for this module.

!Practice the demonstrations.

!Complete the lab.

iv

Module 13: Remoting and XML Web Services

Demonstrations

This section provides demonstration procedures that will not fit in the margin notes or are not appropriate for the student notes.

Remoting

In this demonstration, you will show students how a client application uses

.NET Remoting to make a method call on an object in a server application.

The code for this demonstration is contained in one project and is located in <install folder>\Democode\Mod13\Demo13.1. In addition, the code for the individual demonstration is provided in the student notes.

Using Visual Studio .NET to Create an XML Web Service

In this demonstration, you will show students how to use Visual Studio .NET to create an XML Web service.

The code for this demonstration is contained in one project and is located in <install folder>\Democode\Mod13\Demo13.2. In addition, the code for the individual demonstration is provided in the student notes.

In both of the preceding demonstrations, use the debugger to step through the code while you point out features.

Module 13: Remoting and XML Web Services

v

 

 

 

Module Strategy

Use the following strategy to present this module:

!Remoting

Use the diagram on the Remoting Overview slide to introduce the services that are provided by the Microsoft .NET Framework for use with remoting. You will cover each of these services in more detail in the subsequent slides in this section.

Explain how channels and formatters are used to transmit data. Discuss how the .NET Framework supports server-side and client-side activation of remote objects and describe the differences between server-side and clientside activation.

Explain how to control the lifetime of client-activated remote objects by using a leasing mechanism. Discuss how objects are marshaled in .NET Remoting.

Explain how to register and activate a remote object from the server side and the client side.

Conclude this section with a brief discussion of client compilation techniques.

!Remote Configuration Files

Discuss the use of configuration files in remoting. Do not spend time on the

.NET Remoting configuration file format; instead refer students to the .NET Framework Software Developer’s Guide (SDK) documentation.

Because the module is long, conclude this part of the lecture and instruct students to do Lab 13.1.

!XML Web Services

Explain how to use Visual Studio .NET to implement an ASP.NET XML Web service and how to access the XML Web service from a Web browser and a client application. Use the Using Visual Studio .NET to Create an XML Web Service demonstration to illustrate the concepts that are covered in this section.

Introduce the XML Web service discovery process and the tools that are available for discovery.

Module 13: Remoting and XML Web Services

1

 

 

 

Overview

Topic Objective

To provide an overview of the module topics and objectives.

Lead-in

In this module, you will learn about distributed applications that use .NET Remoting.

!Remoting

!Remoting Configuration Files

!XML Web Services

*****************************ILLEGAL FOR NON-TRAINER USE******************************

Microsoft® .NET Remoting provides a framework that allows objects to interact across remoting boundaries, for example, across application domains (AppDomain).

XML Web services is a term for communication that uses industry-standard HTTP and Simple Object Access Protocol (SOAP) protocols. You can implement XML Web services by using remoting and by using ASP.NET.

After completing this module, you will be able to:

!Write and configure distributed applications that use .NET Remoting.

!Create an XML Web service by using Microsoft Visual Studio® .NET and ASP.NET.

!Consume an XML Web service by using the Web Services Description Language tool (Wsdl.exe).

2Module 13: Remoting and XML Web Services

" Remoting

Topic Objective

To provide an overview of the topics covered in this section.

Lead-in

This section shows how

.NET Remoting supports communication in various scenarios.

!Remoting Overview

!Channels and Formatters

!Activation and Proxies

!Lease-Based Lifetime

!Object Marshaling

!Server Side

!Client Side

!Client Compilation Techniques

*****************************ILLEGAL FOR NON-TRAINER USE******************************

.NET Remoting supports communication in the following scenarios:

!Between objects in different application domains

!In different processes

!On different computers

The common language runtime remoting infrastructure provides a rich set of classes that enable you to ignore most of the complexities of deploying and managing remote objects. Even with applications that run under different runtime environments, the process of calling methods on remote objects is almost identical to the process of calling local methods.

Module 13: Remoting and XML Web Services

3

 

 

 

Remoting Overview

Topic Objective

To provide an overview of

.NET Remoting.

Lead-in

The .NET Framework provides several services that are used in remoting.

Client AppDomain

Client

Formatter

 

Object

 

Server

Channel

Proxy

 

Server AppDomain

Formatter

Server

Channel Object

Remoting Boundary

*****************************ILLEGAL FOR NON-TRAINER USE******************************

The .NET Framework provides several services that are used in remoting:

!Communication channels that are responsible for transporting messages to and from remote applications

!Formatters that encode and decode messages before they are transported by the channel

!Proxies that forward remote method calls to the proper object

!Remote object activation and lifetime support

Note Because the .NET context mechanism is beyond the scope of this course, this module does not cover remoting calls between contexts.

4Module 13: Remoting and XML Web Services

Channels and Formatters

Topic Objective

To explain how channels and formatters are used to transmit data.

Lead-in

Channels are used to transport messages to and from remote objects. Formatters are used to encode and serialize data into messages before transmission over a channel.

!Channels Transport Messages To and From Remote Objects

!Client Selects a Channel That Is Registered on the Server

#Before calling a remote object, the client registers the channel Channels are registered on a per application domain basis

#One computer cannot have multiple channels listening to same port

!.NET Provides Implementation of HTTP and TCP Channels

#HTTP Channel default: SOAP protocol to transport XML messages

#TCP Channel default:TCP protocol to transport binary messages Faster than HTTP SOAP Web Services but not as open

!Example: Programmatic Registration of TCP Channel on Port 8085

using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels;

using System.Runtime.Remoting.Channels.Tcp; using System.Runtime.Remoting.Channels.Tcp;

TcpChannel chan = new TcpChannel(8085); TcpChannel chan = new TcpChannel(8085);

ChannelServices.RegisterChannel(chan);

ChannelServices.RegisterChannel(chan);

*****************************ILLEGAL FOR NON-TRAINER USE******************************

Channels are used to transport messages to and from remote objects. When a client calls a method on a remote object, the parameters, as well as other details that are related to the call, are transported through the channel to the remote object. Any results from the call are returned back to the client in the same way.

Formatters are used to encode and serialize data into messages before they are transmitted over a channel.

Channel Selection

Because a client can use any of the channels that are registered on the server to communicate with a remote object, you can select the channels that best suit your needs. You can also customize any existing channel or build new ones that use different communication protocols.

Channel selection is subject to the following rules:

!Channels must be registered before objects are registered. At least one channel must be registered with the remoting infrastructure before a remote object can be called.

!Channels are registered on a per application domain basis.

A single process may contain multiple application domains. When a process dies, all channels that it registers are automatically destroyed.

!It is not valid to register a channel that listens on the same port on which another channel is currently listening.

Though channels are registered on a per application domain basis, different application domains on one computer cannot register the same channel that listens on the same port.

Module 13: Remoting and XML Web Services

5

 

 

 

Clients can communicate with a remote object by using any registered channel. The remoting framework ensures that the remote object is connected to the proper channel when a client attempts to connect to it. The client is responsible for specifying a channel before it attempts to communicate with a remote object.

To specify a channel, you can use a .NET Remoting configuration file, or you can call the RegisterChannel method on the ChannelServices class.

The .NET Framework provides support for HTTP, TCP, and SMTP channels. Because .NET Remoting channels are pluggable, you can write and plug in additional channels with unique transport and encoding requirements.

Formatters Used to Encode and Decode Messages

Each channel provides a default formatter. However you can specify the formatter that you wish to use.

Note A Uniform Resource Identifier (URI) is a compact representation of a resource that is available to your application through the Internet. You may be more familiar with the term URL, which stands for Uniform Resource Locator. URLs form a subset of the more general URI naming scheme. A URL identifies an Internet resource that has a Web page address.

HTTP Channel

By default, the HTTP channel uses the SOAP protocol to transport messages to and from remote objects. All messages are passed through the SOAP formatter, where the message is changed into XML and serialized, and the required SOAP headers are added to the stream.

Alternatively, you can specify the binary formatter, which results in a binary data stream. In either case, the data stream is then transported to the target Uniform Resource Identifier by using the HTTP protocol. You can create industry-standard XML Web services by using the HTTP channel with the default SOAP formatter.

TCP Channel

By default, the TCP channel uses a binary formatter to serialize all messages to a binary stream and transports the stream to the target Uniform Resource Identifier by using the TCP protocol.

Alternatively, you can specify the SOAP formatter, which results in an XML data stream. You can obtain better performance by using the TCP channel with the default binary formatter than you can by using XML Web services.

6Module 13: Remoting and XML Web Services

Code Example

The following code example shows how to programmatically register a TCP Channel on port 8085 by using ChannelServices.RegisterChannel:

using System;

using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Tcp; //...

TcpChannel chan = new TcpChannel(8085); ChannelServices.RegisterChannel(chan);

//...

Security Issues

If you have a choice between using the HttpChannel and the TcpChannel, it is recommended that you use the HttpChannel and host your remote objects in Internet Information Services (IIS), no matter what the user authentication and authorization models are. IIS hosting provides support for wire-level protection using Secure Sockets Layer (SSL) and authentication using Integrated Windows Authentication (formerly NTLM authentication) or Kerberos. For configuring SSL and authentication, see the IIS documentation.

The TcpChannel, as an implementation of the Transmission Control Protocol (TCP), does not have default support for some of the robust authentication standards that the HTTP standard does. Within a secured environment (one that has wire-level protection such as IPSec), the high-speed TcpChannel can be used, but it is not recommended over the Internet or a nonsecure intranet.

You can use cryptography to protect data from being viewed or modified and thereby provide secure channels of communication over otherwise insecure channels. The System.Security.Cryptography namespace contains a set of classes that allow you to perform both symmetric and asymmetric cryptography, create hashes, and provide random number generation. Successful cryptography is the result of combining these tasks. See the .NET SDK for documentation about the System.Security.Cryptography namespace.

Соседние файлы в папке c#