WROX - C# Web Services - Building Web Services with ASP.NET and.NET Remoting.pdf
(
459 KB
)
Pobierz
12493900 UNPDF
Programmer to Programmer
TM
C#
Building Web Services with
.NET Remoting and ASP.NET
Ashish Banerjee, Aravind Corera, Zach Greenvoss, Andrew Krowczyk,
Christian Nagel, Chris Peiris, Thiru Thangarathinam, Brad Maiani
C#
Web Services
Web Services
Summary of Contents
Introduction
1
Section One
– Getting Started
9
Chapter 1:
What is a Web Service?
11
Chapter 2:
Web Service Protocols
27
Chapter 3:
Web Services and the .NET Framework
49
Section Two
– ASP.NET Web Services
65
Chapter 4:
Building an ASP.NET Web Service
67
Chapter 5:
Consuming ASP.NET Web Services
105
Section Three
– .NET Remoting
129
Chapter 6:
.NET Remoting Architecture
131
Chapter 7:
Web Services Anywhere
175
Chapter 8:
Building a Web Service with .NET Remoting
201
Chapter 9:
Building a .NET Remoting Client
231
Section Four
– Advanced Topics
253
Chapter 10:
Universal Description, Discovery and Integration (UDDI)
255
Chapter 11:
.NET Security and Cryptography
275
Chapter 12:
Web Services As Application Plug-Ins
333
Section Five
– Case Studies
367
Case Study 1:
ASP.NET
369
Case Study 2:
P2P .NET Remoting
423
Section Six
–Appendix
493
Appendix A:
.NET Remoting Object Model
495
Index
581
.NET Remoting Architecture
6
In the last few chapters, we have seen how ASP.NET web services can be created and used. ASP.NET
web services require the ASP.NET runtime as hosting environment. Using .NET Remoting directly, we
can host a web service in any application we want. .NET Remoting allows much more flexibility
because different transport protocols may be used, we can get a performance increase with different
formatting options, and it's possible to host the server in different application types.
The next four chapters will deal with .NET Remoting. In this chapter, we will look at the architecture of
.NET Remoting, and go into detail in the following areas:
❑
What is .NET Remoting?
❑
.NET Remoting Fundamentals
❑
Object Types
❑
Activation
❑
Marshaling
❑
Asynchronous Remoting
❑
Call Contexts
The next chapter will show different application types, transport protocols, and formatting options, and
Chapters 8 and 9 will show an example of using .NET Remoting. Let's begin the chapter with a look at
.NET Remoting.
As with the previous chapters, the code for the examples in this chapter can be downloaded from
http://www.wrox.com
.
Chapter 6
What is .NET Remoting?
.NET Remoting is the replacement for DCOM. As we have seen in the last chapters, ASP.NET web services
are an easy-to use-technology to call services across a network. ASP.NET web services can be used as a
communication link with different technologies, for example to have a COM or a Java client talk to web
services developed with ASP.NET. As good as this technology is, however, it is not fast and flexible enough
for some business requirements in intranet solutions, and ASP.NET web services requires the ASP.NET
runtime. With .NET Remoting we get
Web Services Anywhere
that can run in every application type.
Web Services Anywhere
The term "Web Services Anywhere" means that web services can not only be used in any application, but
any application can offer web services. ASP.NET web services require the IIS to run; web services that make
use of .NET Remoting can run in any application type: console applications, Windows Forms applications,
Windows services, and so on. These web services can use
any transport
with
any
payload encoding
.
In the next chapter we will talk about when and how to use .NET Remoting with different transports
(TCP and HTTP) and about different payload encoding mechanisms (SOAP and binary).
CLR Object Remoting
The next part of .NET Remoting that we need to be aware of is
CLR Object Remoting.
With CLR
Object Remoting we can call objects across the network, as if they were being called locally.
With CLR Object Remoting we have:
❑
Distributed Identities
– Remote objects can have a distributed identity. If we pass a reference
to a remote object, we will always access the same object using this reference.
❑
Activation
– Remote objects can be activated using the
new
operator. Of course, there are
other ways to activate remote objects, as we will see later.
❑
Lease-Based Lifetime
– How long should the object be activated on the server? At what time
can we assume that the client no longer needs the remote object? DCOM uses a ping
mechanism that is not scalable to internet solutions. .NET Remoting takes a different
approach with a lease-based lifetime that is scalable.
❑
Call Context
– With the SOAP header, additional information can be passed with every
method call that is not passed as an argument.
We will cover all of these CLR Object Remoting features in detail later on in this chapter.
.NET Remoting Fundamentals
The methods that will be called from the client are implemented in a remote object class. In the figure
opposite we can see an instance of this class as the Remote Object. Because this remote object runs inside a
process that is different from the client process – usually also on a different system – the client can't call it
directly. Instead the client uses a
proxy
. For the client, the proxy looks like the real object with the same
public methods. When the methods of the proxy are called,
messages
will be created. These are serialized
using a
formatter
class, and are sent into a
client channel
. The client channel communicates with the server
part of the channel to transfer the message across the network. The
server channel
uses a
formatter
to
deserialize the message, so that the methods can be dispatched to the
remote object
:
132
.NET Remoting Architecture
Client Process
Server Process
Proxy
Remote Object
Formatter
Formatter
Client Channel
Sever Channel
In the simplest case, we have to create a remote object class and instantiate a channel for a .NET
Remoting application. The formatter and the proxy will be supplied automatically. The architecture is
very flexible in that different formatters and channels can be used. We cover the use of the TCP and
HTTP channels, and the SOAP and binary formatters in the next chapter.
In the next section we'll start with the simplest case to develop a remoting object, server, and client. In
this section we will not go into the details of the remoting architecture, as we will cover this later after
we've finished a simple client and server.
Remote Object
A remote object is implemented in a class that derives from
System.MarshalByRefObject
.
MarshalByRefObject
defines methods for lifetime services that will be described later when we use
the leasing features. A remote object is confined to the application domain where it is created. As we
already know, a client doesn't call the methods directly; instead a proxy object is used to invoke
methods on the remote object. Every public method that we define in the remote object class is
available to be called from clients.
What is an
application domain
? Before .NET, processes were used as a security boundary so that one
process couldn't crash another process because it used private virtual memory. With the help of the
managed environment of .NET, the code of an application can be checked, and there's no way to crash the
process. To reduce the overhead with different processes, the concept of an application domain was
introduced with .NET. Multiple applications can run in the same process without influencing each other
if they are called within different application domains. If one of these applications throws an exception
that isn't handled, only the application domain is terminated, and not the complete process. To invoke a
method in an object running in a different application domain, .NET remoting must be used.
The following code sample shows a simple remote object class, and the code for this simple example can be
found in the
SimpleTest
folder of the code download for this chapter, which is available from
http://www.wrox.com
. The method
Hello()
is declared public to make it available for a remoting client:
// MyRemoteObject.cs
using System;
namespace Wrox.Samples
{
133
Plik z chomika:
pawellop2m
Inne pliki z tego folderu:
2524 Developing XML Web Services Using Microsoft ASP.NET.zip
(15862 KB)
41.Wrox.Professional.DotNetNuke.ASP.dot.NET.Portals.May.2005.eBook-DDU.pdf
(11071 KB)
Apress - Pro Asp Net 3.5 In C# 2008, Second Edition.pdf
(52741 KB)
APress - Real World ASP.NET - Building a Content Management System (Source Code) (VBL).zip
(1758 KB)
APress - Real World ASP.NET - Building a Content Management System (VBL).pdf
(4485 KB)
Inne foldery tego chomika:
Pliki dostępne do 21.01.2024
!!! NOWOŚCI FILMOWE 1080p
100 Najlepszych Filmów Polskich
100 Najlepszych Filmów Świata
4000 FiLMÓW DOKUMENTALNYCH I POPULARNO-NAUKOWYCH !!!
Zgłoś jeśli
naruszono regulamin