Title: .NET Remoting
1(No Transcript)
2.NET Remoting(?????????? ?????????)
???????????? ?? .NET Framework
http//www.nakov.com/dotnet/
??????? ?????
?????????? ???????? ?? ?????????? ?? ???????
academy.devbg.org
3?????????? ??????
- ?????? ???????? ?? .NET Framework
- ?????? ???????? ?? ????? C
- ?????? ???????? ?? ?????????? ????? ? ????????
?????????? - ?????? ???????? ?? ???????????? ??????????? ?
??????? - ???????? ?? ?????????????? ? .NET
4??????????
- ????? ? .NET Remoting?
- Remoting ????????????????
- Remoting ?????? ? ?????????. ??????????? ?? ?????
- ????????? ?? ??????. ????????? ?? ???????.
????????? ?? ??????? - ???????????? (Marshaling). Marshal-by-Value
??????. Marshal-by-Reference ?????? - ????? ?? ???????? (Lifetime). ILease
- ????????? ?? Remoting ?????? ? ??????
- ????????? ? ?????? ??????
- Remoting ??????????????? ????
5???????????? ??????????
- ???????? ?????? ?????????? ?? ????????????
- ??????? ?? ?? ??????? ??????????? ??????????,
????? ?? ?????????????? - ?????? ?? ???????????? ??????????
- ????? "??????/??????"
- ????? "???????????? ??????"
- DCOM ?????? ?? ? Microsoft Windows
- CORBA ??????? ????????, ????? ??????
- Java RMI ?????? ?? ?? Java ????????????
- .NET Remoting ?????? ?? ? .NET Framework
- ????? "Web ??????"
6????? ? .NET Remoting?
- Remoting ???????????? ? .NET Framework ?????????
????????? ?????? ?? ?????????? ?????? - ?????? ?? ???? application domain
- ?????? ?? ???? ??????
- ?????? ?? ?????????? ??????
- ???????? ?? ?? ?????????? ?? ????????????? ???
???????????? ?????????? - .NET Framework ?????????? ??????????????
?????????????? ?? Remoting ????????????
7Remoting ????????????????
- .NET Remoting ???????????????? ?? ?????? ??
- ?????? ???????? ????????? ?? ? ??? ??????????
?????? - ????????? ??????? ? ????????? ??????????? ?
??????? ?????? - ?????? ??????? ???????? ???????????? ?? ??????
??? ???????????? ?????? - ????????? ?? ????????? ?????????? ??????????
???????????? ?? ?????? - ???????????? ????????? ?????? ?? ??????,
??????? ????????, ?????? ? ?.?.
8Remoting ???????????????? (2)
9Remoting ??????
- ???????? (channels) ? .NET Remoting
- ????????????? ????????? ?? ? ??? ??????????
?????? - ????? ?? ?????
- TCP ????????? ???? TCP ?????
- HTTP ????????? ????????? HTTP
- ????? ?????????? ?? ???????????
- ????????? ?? ????? ?? ???????????, ???? ? ??
?????????? ?????????? - ????????? TCP ???????
- ?????? ?? ????? ???????????? ????? ??????????
10??????????? ?? ?????
- ????????????? ?? Remoting ????? ???? ?? ????? ??
2 ?????? - ???? ????? System.Runtime.Remoting.
Channels.ChannelServices - ???? ??????????????? ????
using System.Runtime.Remoting.Channelsusing
System.Runtime.Remoting.Channels.TcpTcpChannel
channel new TcpChannel(3333)ChannelServices.R
egisterChannel(channel)
RemotingConfiguration.Configure(
"MyClient.exe.config")
11?????????
- ??????????? (formatters) ?????????? ???????????,
????? ?? ???????? ?? Remoting ???????? - ??????????? ?????
- ??????? ????????
- ?????? ????????????????
- ????? ???????????? ? ????? ?????????? (??????????
?? .NET Remoting) - SOAP ????????
- XML ??????? ?????? ????? ???????????? ? ?????
?????????? - ??-???? ????????????????
12????????? (2)
- ????????? ?? ????????????
- HTTP ???????? ????????? ?? ???????????? SOAP
???????? - ???? ????????? ?????????? ?? ??????????? ?????
???? Web ?????? - TCP ???????? ????????? ?? ???????????? ???????
???????? - ????? ?? ?? ??????? ? ?????
SoapServerFormatterSinkProvider provider
new SoapServerFormatterSinkProvider() IDictionary
props new Hashtable() props"port"
12345 TcpChannel chan new TcpChannel(props,
null, provider)
13????????? ?? ??????
- "?????????" ???????? ????????? ?? ????????? ?????
(????????????) ? ?????????? ?? ?????? ??
?????????? - ??????????? ???? ??? ????
- ????????? ?? ?????? ?? ??????? (server-side
activation) - ????????? ?? ?????? ?? ??????? (client-side
activation) - ?????? ?? ?????????
- ???? ????????? new
- ???? Activator.GetObject()
- ???? Activator.CreateInstance()
14????????? ?? ?????? (2)
- ??? ????????? ?? ????????? ????? Remoting
???????????????? ????????? ??????? ?????? ????
??? ??????? - ?????? ?????? ???????? ???? ????????? ???? (???
?????????), ?? ???????? ??????????? ???
??????????? ????? - ?????? ?? ??????, ????????, ??????? ? ?????
??????? - ????????? ?? ??????
- ???????????? ??????????
- ?? ??????????? ?????????????? ?? ?????? ?
?????????
15????????? ?? ???????
- ??? ????????? ?? ??????? (server-side activation)
- ???????? ??????? ??????????? ?????? ??? ?????????
?????? - ??? ??? ?????? ?? ???????? ?????????
- Single-Call ?? ????? ????????? ?????? ??
??????? ??????? ????????? - Singleton ???? ? ???? ????????? ???????? ??????
??????? - ??????????? ?? ??????? ???? ??????
- ??????? ?? ??????????? ?? ???? (?????????) ??
?????? ???????
16????????? ?? ??????? (2)
- ???????? ?????? ?? ????? ?????, ?? ???????
???????? ????????? - ???????????? ?? Single-Call server activated
object - ???????????? ?? Singleton server activated object
RemotingConfiguration.RegisterWellKnownServiceType
( typeof(CommonTypes.Library), "Library",
WellKnownObjectMode.SingleCall)
RemotingConfiguration.RegisterWellKnownServiceType
( typeof(CommonTypes.Library), "Library",
WellKnownObjectMode.Singleton)
17????????? ?? ???????
- ??? ????????? ?? ??????? (client-side activation)
- ???????? ?? ???????? ?? ?????? ?? ??????? (?????,
???????) - ????? ?????? ?? ????????? ?? ????? ??????? ????,
??????? ????????? - ????? ?????? ?????? ??? ???? ????????? ?????? ??
??????? - ???????????? ?? client-activated ?????
RemotingConfiguration.RegisterActivatedServiceType
( typeof(CommonTypes.Library))
18???????????? (Marshaling)
- ?????????????? ????????? ?????? ?? ?????? ?????
Remoting ??????? ? ???????. ???????? ??? - ????????? ?? ?????????
- ??????? ?? ????????
- ?????? ?? ???????? ? ??????
- ??? 3 ???? ??????
- Marshal-by-Value ?????? ???????? ?? ?? ????????
(?????????????) - Marshal-by-Reference ?????? ???????? ?? ??
?????????? ?????????? (ObjRef) - Not-Marshaled ?????? ?? ?? ????????
19Marshal-by-Value ??????
- Marshal-by-Value ??????
- ?????? ?????????????? ?????? (Serializable,
ISerializable) - ???????? ?? ?? ???????? (????? ?? ??? ?? ????????
?? ???????????? ??????) - ??? ??????? ?? ??????? ???? ????????? ????? ??
?????? - ???????? ?? ?????? ? ???????? ?? ????????
???????? ?????? ?????
Serializable public struct Book public
string mAuthor public string mTitle
20Marshal-by-Reference ??????
- Marshal-by-Reference ??????
- ?????? ??????, ????? ?????????? ?????
System.MarshalByRefObject (???????????
?????????????? ??????) - ???????? ?? ?? ?????????? ??????????, ?? ????? ??
??????? ?????? ???? - ?????? ???????? ?? ???????? ??? ??????????? ?????
???? ?????? ????? - ????? ?????? ??? ??????? ?? ???? ??? ????????
??????????? ?????????? ????????? ????
????????????????
public class Book MarshalByRefObject
21????? ?? ???????? (Lifetime)
- ? .NET Remoting ?? ???????? ?????????
"lease-based lifetime" ("?????, ???????? ??????") - ???????? ?? ???? ??? Singleton Server-Activated
?????? ? Marshal-by-Reference Client-Activated
?????? - ??? ????????? ?? ????? ?? ?? ???? "????? ??
?????" - ???? ???????? ?? ???? ????? ??????? ?? ?????????
?? Garbage Collector-? - ??????? ?? ????? ?? ????????? ??? ????????? ??
?????? ? ?? ???? ?? ?? ??????? ???? ????
22??????????? ILease
- InitialLeaseTime ??????? ????? (5 ???. ??
????????????) - RenewOnCallTime ?????????? ?? ?????? ???
????????? (2 ???.) - SponsorshipTimeout ????????? ?? ?. ???.
"????????" (2 ???.) - CurrentLeaseTime ???????? ?????
- CurrentState ????????? ?? ??????? ?? ?????
(Initial, Active, Expired, Renewing)
ClientActivatedType caObject new
ClientActivatedType() ILease serverLease
(ILease) RemotingServices.GetLifetimeService(c
aObject) serverLease.RenewOnCallTime new
TimeSpan(0, 10, 0) // 10 min.
23????????? ?? Remoting ??????
- ???????????? ?? Remoting ?????
- ???????????? ?? ????????, ????? ?? ????? ????????
?????????? - ????????? ?? ????????? ????? (?? ?? ?? ???????
????????????)
TcpChannel channel new TcpChannel(12345) Channe
lServices.RegisterChannel(channel)
RemotingConfiguration.RegisterWellKnownServiceType
( typeof(CommonTypes.Library), "Library",
WellKnownObjectMode.Singleton)
Console.ReadLine() // ??? System.Threading.Threa
d.CurrentThread.Suspend()
24????????? ?? Remoting ??????
- ???????????? ?? Remoting ?????
- ?????????? ?? ????????? ?????
- ??? ????
- ?????????? ?? ??????????? ?????
TcpChannel channel new TcpChannel() ChannelServ
ices.RegisterChannel(channel)
Library remoteLibrary (Library)
Activator.GetObject(typeof(Library),
"tcp//localhost12345/Library")
RemotingConfiguration.RegisterWellKnownClientType(
typeof(CommonTypes.Library),
"tcp//localhost12345/Library") Library
remoteLibrary new Library()
25????????? ? ?????? ??????
- ???????????? ??? Remoting ?????? ?????? ?? ??
???????? ???????????? ?? ??????? ? ?? ??????? - ??? ??????? ???????
- ?????? ?????? ?? ??????? ? ??????? ??????? (.DLL
????) - ? Class Library ?????? ??? VS.NET
- ?????? ?? ?????????? ??? ???? DLL
- ?????? ?????? ?? ????????? ???? ??????????, ?????
?? ??????? ? ??????? ???????
26???????????? 1
- ?????????? ?????? ????? Remoting ??????????
(?????? ??????)
27?????? ?????????????
- ??????????????? ?? Remoting ???????????????? ????
?? ????? ? ?????? ?? ???????????? ???? - ????????????????? ???? ???? ?? ???????
- ?????? ? ?????????
- ????? ?? ????? (lease-based lifetime)
- ??????????? ?? ????????? ??????
- ??????????? ?? ?????????? ??????
- ??????? ?? ????????? (???????)
RemotingConfiguration.Configure("MyConfig.xml")
28Remoting ??????????????? ???? ??????
ltconfigurationgt ltsystem.runtime.remotinggt lta
pplicationgt ltservicegt lt!-- set the
activation mode, remotable object
and its URL --gt ltwellknown
mode"Singleton" type"CommonTypes.Libr
ary" objectUri"Library"
/gt lt/servicegt ltchannelsgt lt!--
set the channel and port --gt ltchannel
ref"tcp" port"12345" /gt lt/channelsgt lt/
applicationgt lt/system.runtime.remotinggtlt/config
urationgt
29.NET Remoting(?????????? ?????????)
????????
30??????????
- ???????? ????????? ????????? ?? .NET Remoting
???????????????? ??????, ?????????, ??????
?????????, ?????? ???????????? ? ?????? ????? ??
????????. - ???????????? ??????-?????? ?????????? ??
????????? ? ?????? ????? (chat), ???????? ?? .NET
Remoting. ??????????? TCP ?????, ???????
????????, ???????????? ?? ?????????? ? Singleton
????????? ?? ???????. ???????? ?????? ?? ????????
?????? ?? ?????????? ??? ???? ??????????? ? ??
????????? ??????? ????????? (chat ?????)
????????????. ???????? (Windows Forms ??????????)
?????? ?? ???? ?? ??????? chat ?????, ?? ???????
????????? ?? ??????? ??????????? ? ?? ???????
chat ?????.
31??????????
- ???????????? ??????-?????? ??????????, ????????
?? .NET Remoting ???????????? ?? ?????????? ??
?????????? ? ?????? ??? ??????. ???????? ??????
?? ???????? ?????????? ????????? ?? ????????,
????????? ?? ???????? ?? ????? ?????, ???????? ??
?????, ???????? ?? ??????, ????????? ?? ?????,
????????? ?? ??????, ??????????? ?? ?????? ? ????
?????. ???????? ?? ????? ?? ????? ??????? ???? ?
????. ??????????? ????????? ??????? ?? ??????????
?? ???????? ??? ????????. ???????? ?????? ?? ?
Windows Forms ?????????? ? ?? ??????????
????????? ??? ?????????? ????????. ???????????
HTTP ?????, SOAP ????????, ????????? ?? ??????? ?
???????????? ?? ????????. ??????????????? ??
??????? ? ??????? ?????? ?? ????? ? ?????? ????.
32?????????? ??????????
- ????? ????????, Remoting http//www.nakov.
com/dotnet/2003/lectures/Remoting.doc - Lester Temple, Introduction to .NET Remoting
http//www.ilmservice.com/twincitiesnet/Presentati
ons/RemotingIntro.ppt - MSDN Library http//msdn.microsoft.com