Professional Documents
Culture Documents
| |
Understanding .NET Remoting
Implementing Server-Activated and Client-Activated
Objects
Transporting Messages Across Application Domains Using
Channels
Configuring and Securing .NET Remoting Objects
3
x 0
|
|
|
|
x 0
½
½
x
x 0
x
0
J ½
| ½
x 0
½ |
|
|
|
|
x 0
½ |
|
| |
|
x
0
3
½
x
0
½
u Objects are created on the server when you call a method in the server class
u There are two ways to create a server-activated object :
Singleton
SingleCall
public class SSNServer
{
public SSNServer()
{ RemotingConfiguration.ApplicationName = "testService"; Re
motingConfiguration.RegisterèellKnownServiceType(
typeof(testService), "MyUri",èellKnownObjectMode.Singleton);
}
}
x
0
| ½
|
|
x
0
½
|
|
x
0
|
RemotingConfiguration.RegisterèellKnownServiceType(RemoteTier,U
RI,ObjectMode)
RemotingConfiguration.RegisterèellKnownClientType(RemoteTier,URL)
x
0
TcpServerChannel channel;
channel = new TcpServerChannel(port)
ChannelServices.RegisterChannel(channel, false)
RemotingConfiguration.ApplicationName = _
³Option"
RemotingConfiguration.RegisterèellKnownServiceType( _
typeOf(RemoteTier.ClassRemote), _
³URI", èellKnownObjectMode.Singleton)
x
0
|
TcpClientChannel channel;
ChannelServices.RegisterChannel(channel, false)
RemotingConfiguration.RegisterèellKnownClientType( _
typeOf(RemoteTier.ClassRemote), _
"TCP://IPAddress:8066/URI")
x
0
|
x
0
|
|
x 0
å|
x
0
|
u Application
Thu;c tính: Name
u Service
u èellknown
Thu;c tính:
mode="Singleton"
objectUri=³URI"
type="RemoteTier.clsRemote, clsRemote"
u Channels
u Channel
Thu;c tính: ref, port, displayName
x 0
|
iconfiguration>
isystem.runtime.remoting>
iapplication name="RemoteName">
iservice>
iwellknown mode="Singleton" objectUri=³URI"
type="RemoteTier.clsRemote, clsRemote"/>
i/service>
ichannels>
ichannel ref="http" port="8081"
displayName=³Http Channel " />
i/channels>
i/application>
i/system.runtime.remoting>
i/configuration>
x 0
RemotingConfiguration.Configure(³FileNameServer.exe.config")
x 0
||
|
|
x 0
å| |
x 0
| |
u Application
Thu;c tính: Name
u Service
u èellknown
Thu;c tính:
mode="Singleton"
URL=³URL"
type="RemoteTier.clsRemote, clsRemote"
u Channels
u Channel
Thu;c tính: ref, port, displayName
x
0
| |
iconfiguration>
isystem.runtime.remoting>
iapplication>
iclient>
iwellknown mode="Singleton"
url="http://localhost:8080/RemoteName/URI" type="RemoteTier.clsRemote,
clsRemote"/>
i/client>
ichannels>
ichannel ref="http" displayName="HTTP Channel " />
ichannel ref="tcp" displayName="TCP Channel " />
i/channels>
i/application>
i/system.runtime.remoting>
i/configuration>
x 0
RemotingConfiguration.Configure(³FileNameClient.exe.config")
x 0
3
!!
x 0
J"!!
u To initialize a lifetime lease, you override the InitializeLifetimeService function of the MarshalByRefObject class
using System;
using System.Runtime;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Lifetime;
public class MyLifetimeControlObject: MarshalByRefObject
{
public override object InitializeLifetimeService()
{
ILease lease = (ILease)base.InitializeLifetimeService();
if (lease.CurrentState == LeaseState.Initial)
{
lease.InitialLeaseTime = TimeSpan.FromMinutes(2);
lease.SponsorshipTimeout = TimeSpan.FromMinutes(3);
lease.RenewOnCallTime = TimeSpan.FromSeconds(3);
}
return lease;
}
}
x
0
!!
x 0
#
x 0
$
½
½
3
|
u Understanding Channels
u Channel Interfaces
u Registering a Channel
u Selecting Channels for Remoting
u HTTP Channels
u TCP Channels
x 0
3
|
x 0
|J
x 0
|
!"
x
0
|
u $ou should apply the following rules when selecting channels for
remote objects:
Register a server channel:TcpServerChannel or HttpServerChannel,
before registering a remote object
Register a server channel on the client computer
Channel names within an application domain cannot be the same
Two channels registered with the remoting system on a computer cannot
listen on the same port.
x 0
A#|
x 0
A#|
%
&
x 0
|#|
u TCP Channel is the same HTTP Channel. $ou can see page
238-239.
x
0
J
x 0
3
u èhat is Delegate?
u A delegate is a class that holds a reference to the method that is called when an event is
fired .
u To declare Delegates:
public delegate void RetirementHandler(object sender, RetireEventArgs e);
u To define define method to which the event delegate points
public class Action
{
public void RetireEvent (object sender, RetireEventArgs e)
{}
}
u To create an instance of the delegate and store the address of the method whose
reference the delegate holds.
Action a = new Action();
NewEventHandler handler = new RetirementHandler(a.RetireEvent);
x 0
J
½
u èhen you implement events and delegates in remoting
applications, you should ensure that:
The delegates you pass to the server for callback functions are
delegates to instance members because you cannot call static
members remotely.
$ou register a channel to listen for the callback function.
x 0
J
½
% &
u $ou must perform the following tasks to enable delegates to
listen for events in the remoting application:
Define an event and the extension to the EventArgs class that the event
passes to a delegate.
Define a delegate that wraps an event-handler method of the signature
required by the event.
Define a method that handles the event.
Initialize a delegate that wraps the event-handler method.
Add the delegate to the event.
x 0
|
iconfiguration>
isystem.runtime.remoting>
iapplication>
iservice>
iwellknown mode = "SingleCall" type = "MyRemoteClass,RemoteAssembly"
objectUri = "MyApp.rem" />
iactivated type="ClientActivatedType, TypeAssembly" />
i/service>
i/application>
i/system.runtime.remoting>
i/configuration>
x 0