Your SlideShare is downloading. ×
0
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
C sharp
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

C sharp

1,962

Published on

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,962
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
256
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Programming with C# and .NET
  • 2. Outline <ul><li>Demo </li></ul><ul><li>.NET introduction </li></ul><ul><li>C# Programming </li></ul>2 3 1 4 .NET Remoting
  • 3. Programming with C# and .NET Demo
  • 4. The Basic Idea <ul><li>C# is the programming language that I </li></ul><ul><li>am long waiting for, because my bad </li></ul><ul><li>MFC experience. </li></ul><ul><li>Question: How to use C# to do </li></ul><ul><ul><li>Image Processing </li></ul></ul><ul><ul><li>OpenGL Programming(3D Graphics) </li></ul></ul><ul><ul><li>DirectX Programming </li></ul></ul><ul><li>SEE DEMO </li></ul>
  • 5. Programming with C# and .NET .NET
  • 6. <ul><li>CLR </li></ul><ul><ul><li>C ommon L anguage R untime </li></ul></ul><ul><ul><li>a runtime environment </li></ul></ul><ul><ul><li>concept similar to JVM </li></ul></ul><ul><li>FCL </li></ul><ul><ul><li>F ramework C lass L ibrary </li></ul></ul><ul><ul><li>built on top of the CLR </li></ul></ul><ul><ul><li>provide services for modern applications </li></ul></ul>Major Components
  • 7. Applications written in J# .NET, VB .NET, or C# .NET Framework Overview CLR FCL Windows Operating System (Windows ME, 98, 2000, XP etc) Windows API
  • 8. MSIL <ul><li>M icro s oft I ntermediate L anguage </li></ul><ul><li>a CPU independent set of instructions </li></ul><ul><li>.NET compliant language compile into </li></ul><ul><li>MSIL </li></ul><ul><li>similar to Java Byte Code </li></ul><ul><li>sometimes abbreviated as IL </li></ul>
  • 9. C# VB .NET Visual J# .NET MSIL Linux native code .NET Windows native code Mac OS native code Compile into MSIL CLR do this Support now Will Support soon Will Support soon
  • 10. Java Java Byte Code Linux native code Java Windows native code Mac OS native code JVM do this
  • 11. .NET Compliant Languages <ul><li>Any language that can be compiled into </li></ul><ul><li>MSIL is called a .NET compliant language </li></ul><ul><li>APL, Pascal , Perl , Python , Scheme, Eiffel, </li></ul><ul><li>Fortran , Java , Jscript, Haskell, COBAL , </li></ul><ul><li>RPG, APL, Smalltalk, Component Pascal, </li></ul><ul><li>Curriculum, Mercury, Oberon, Oz, VB .NET </li></ul><ul><li>, C# , Visual C++ .NET , Visual J# .NET , … </li></ul>
  • 12. MSIL Advantages <ul><li>Portability between OS </li></ul><ul><ul><li>.NET compliant language are all compiled into </li></ul></ul><ul><ul><li>MSIL (portable between OS) and can be further </li></ul></ul><ul><ul><li>compiled into native OS machine codes by CLR </li></ul></ul><ul><li>Language Interoperability </li></ul><ul><ul><li>Different languages can communicated easily </li></ul></ul><ul><ul><li>MSIL codes from different languages can be </li></ul></ul><ul><ul><li>linked together to form a program </li></ul></ul>
  • 13. C# VB .NET Visual J# .NET Interoperability Windows native code Compile into MSIL linked the MSIL codes CLR generated a single application (native code) MSIL MSIL MSIL
  • 14. <ul><li>Rules defined in </li></ul><ul><ul><li>C ommon T ype S ystem ( CTS ) </li></ul></ul><ul><ul><li>C ommon L anguage S pecification ( CLS ) </li></ul></ul><ul><li>Cross-language development </li></ul><ul><ul><li>Cross-language Debugging </li></ul></ul><ul><ul><li>Cross-language Exception Handling </li></ul></ul><ul><ul><li>Cross-language Inheritance </li></ul></ul>Language Interoperability
  • 15. Common Type System (CTS) <ul><li>To unify the data types </li></ul><ul><ul><li>Common data types play an important role in </li></ul></ul><ul><ul><li>language interoperability </li></ul></ul><ul><li>Types can be of two types </li></ul><ul><ul><li>Value Type </li></ul></ul><ul><ul><li>Reference Type </li></ul></ul>
  • 16. .NET vs. Java <ul><li>Runtime environment </li></ul><ul><ul><li>.NET  CLR </li></ul></ul><ul><ul><li>Java  JVM </li></ul></ul><ul><li>Intermediate Code </li></ul><ul><ul><li>.NET  MSIL </li></ul></ul><ul><ul><li>Java  Java Byte Code </li></ul></ul><ul><li>Support </li></ul><ul><ul><li>.NET  Multiple Languages , Multiple Platform </li></ul></ul><ul><ul><li>Java  Single Language , Multiple Platform </li></ul></ul>
  • 17. CLR <ul><li>Load and execute the C # program </li></ul><ul><li>Compile the MSIL into native code </li></ul><ul><ul><li>use Just-in-Time (JIT) compilers </li></ul></ul><ul><li>Garbage Collection </li></ul><ul><ul><li>use Garbage Collector (GC) </li></ul></ul><ul><li>Security Management </li></ul><ul><li>Exception Handling </li></ul>
  • 18. Managed vs. Unmanaged Code <ul><li>Managed Code </li></ul><ul><ul><li>executed under the control of CLR , and use </li></ul></ul><ul><ul><li>the .NET Framework libraries . </li></ul></ul><ul><li>Unmanaged Code </li></ul><ul><ul><li>does not execute under the CLR </li></ul></ul><ul><li>It is possible for managed and unmanaged </li></ul><ul><li>code to work together </li></ul>
  • 19. FCL <ul><li>concept similar to MFC for Windows </li></ul><ul><li>programming </li></ul><ul><li>FCL classes are grouped by namespaces and </li></ul><ul><li>exported by assemblies </li></ul><ul><ul><li>namespace similar to Java package </li></ul></ul><ul><ul><li>assembly similar to .dll </li></ul></ul>
  • 20. <ul><li>Some Namespaces in FCL (has hierarchy) </li></ul><ul><ul><li>System </li></ul></ul><ul><ul><li>System.IO </li></ul></ul><ul><ul><li>System.Windows.Forms </li></ul></ul><ul><ul><li>System.Drawing </li></ul></ul><ul><li>Example: </li></ul><ul><ul><li>System.Windows.Forms is located in </li></ul></ul><ul><ul><li>System.Windows.Forms.dll </li></ul></ul>FCL
  • 21. CLR vs. CLI <ul><li>CLI (Common Language Infrastructure) </li></ul><ul><li>CLR vs. CLI </li></ul><ul><ul><li>CLI is the rule </li></ul></ul><ul><ul><li>CLR is the implementation </li></ul></ul><ul><li>your own CLR </li></ul><ul><ul><li>You can implement your own CLR according </li></ul></ul><ul><ul><li>the CLI </li></ul></ul>
  • 22. MSIL vs. CIL <ul><li>CIL (Common Intermediate Language) </li></ul><ul><li>MSIL vs. CIL </li></ul><ul><ul><li>CIL is the rule </li></ul></ul><ul><ul><li>MSIL is the implementation </li></ul></ul><ul><li>your own IL </li></ul><ul><ul><li>You can implement your own IL according </li></ul></ul><ul><ul><li>the CIL </li></ul></ul>
  • 23. Web Services <ul><li>ASP .NET </li></ul><ul><ul><li>host on IIS server </li></ul></ul><ul><li>.NET Remoting </li></ul><ul><ul><li>can host on any type of applications </li></ul></ul>
  • 24. Programming with C# and .NET C# Windows Programming so easy!
  • 25. Anders Hejlsberg <ul><li>Creator of </li></ul><ul><ul><li>C# </li></ul></ul><ul><ul><li>Turbo Pascal </li></ul></ul><ul><ul><li>Delphi </li></ul></ul><ul><li>Anders studied engineering at the Technical </li></ul><ul><li>University of Denmark , previously worked for </li></ul><ul><li>Borland, now works for Microsoft. </li></ul>
  • 26. Special features <ul><li>Properties </li></ul><ul><li>Indexers </li></ul><ul><li>Delegates and Events </li></ul><ul><li>Operator Overloading </li></ul><ul><li>Reflection </li></ul><ul><li>Attributes </li></ul><ul><li>Formatting </li></ul><ul><li>Regular Expression </li></ul>
  • 27. <ul><li>Pointer </li></ul><ul><li>Miscellaneous features </li></ul><ul><ul><li>jagged array </li></ul></ul><ul><ul><li>foreach loop </li></ul></ul><ul><ul><li>Runtime type identification (RTTI) </li></ul></ul><ul><ul><li>goto </li></ul></ul><ul><ul><li>structure (not the same with C/C++) </li></ul></ul>
  • 28. Start Programming
  • 29. 1. Simple Console Program <ul><li>Visual Studio .NET IDE introduction </li></ul><ul><li>C# program overview </li></ul><ul><li>System.Console.WriteLine(…); </li></ul><ul><li>Build and Run C# program </li></ul>namespace class method link
  • 30.  
  • 31.  
  • 32.  
  • 33.  
  • 34.  
  • 35.  
  • 36. 2. Rapid Application Development <ul><li>RAD like Visual Basic and Borland C++ </li></ul><ul><li>Builder </li></ul><ul><li>concise syntax as Java </li></ul><ul><li>event-driven programming style </li></ul>link
  • 37.  
  • 38.  
  • 39.  
  • 40.  
  • 41.  
  • 42.  
  • 43.  
  • 44.  
  • 45.  
  • 46. 3. Use Assembly <ul><li>classes may be compiled into .exe or .dll , </li></ul><ul><li>such files are called assemblies and are the </li></ul><ul><li>packaging units of C# </li></ul><ul><li>An assembly is composed of four sections </li></ul><ul><ul><li>manifest </li></ul></ul><ul><ul><li>type matadata </li></ul></ul><ul><ul><li>program code (in MSIL format) </li></ul></ul><ul><ul><li>resources used by the program </li></ul></ul>link
  • 47. <ul><li>Manifest </li></ul><ul><ul><li>contain information about the assembly itself </li></ul></ul><ul><li>Type matadata </li></ul><ul><ul><li>information about the data types used by the </li></ul></ul><ul><ul><li>program </li></ul></ul><ul><li>Program Code </li></ul><ul><ul><li>stored in MSIL format </li></ul></ul><ul><li>Resources used by the program </li></ul><ul><ul><li>such as .bmp or .jpg files </li></ul></ul>
  • 48.  
  • 49.  
  • 50.  
  • 51.  
  • 52. 4. Namespaces <ul><li>Namespace prevent name conflicts </li></ul><ul><li>A namespace can be </li></ul><ul><ul><li>split over several files </li></ul></ul><ul><ul><li>separated within the same files </li></ul></ul><ul><li>Namespaces can be nested </li></ul>
  • 53. Example 1 A namespace split over several files link
  • 54.  
  • 55. Example 2 Namespaces Prevent Name Conflicts link The same class name The same method name
  • 56. Example 3 Namespaces Can Be Nested link
  • 57.  
  • 58. 5. Properties <ul><li>Question: </li></ul><ul><li>How do you access private data in Java? </li></ul><ul><li>Properties provide the illusion that we </li></ul><ul><li>can use private data directly </li></ul>
  • 59. <ul><li>example: </li></ul>Property
  • 60. Example 1 link
  • 61. 6. Indexers <ul><li>An indexer allows an object to be indexed like an array </li></ul><ul><li>example: </li></ul>
  • 62. Example 1 link
  • 63. set get
  • 64. 7. Delegate & Event <ul><li>A delegate is an object that can refer to a method </li></ul><ul><li>A delegate can invoke </li></ul><ul><ul><li>instance method associated with an object </li></ul></ul><ul><ul><li>static method associated with a class </li></ul></ul><ul><li>A delegate is similar to a function pointer in C/C++ </li></ul><ul><li>A delegate supports Multicasting </li></ul>
  • 65. <ul><li>An object that has an interest in an event registers an handler for that event </li></ul><ul><li>When the event occurs , all registered handlers are called. </li></ul><ul><li>Event handlers are represented by delegate . </li></ul><ul><li>You can use event accessors to change the way the event handlers are add to or remove from the invocation list </li></ul>
  • 66. Example 1 link Call instance method
  • 67. Instance method
  • 68. Example 2 Call class static method link
  • 69. class static method
  • 70. Example 3 Delegate supports multicasting link
  • 71.  
  • 72.  
  • 73. Example 4 Simple Event & Delegate Demo link Delegate Class static method
  • 74. 8. RTTI <ul><li>Runtime type identification(RTTI) allows the type of an object to be determined during program execution . </li></ul><ul><li>There are three keywords support RTTI </li></ul><ul><ul><li>is </li></ul></ul><ul><ul><li>as </li></ul></ul><ul><ul><li>typeof </li></ul></ul>
  • 75. Example 1 RTTI Demo link
  • 76.  
  • 77. 9. Reflection <ul><li>System.Type is at the core of the reflection sub-system </li></ul><ul><li>Remember </li></ul><ul><ul><li>using System.Reflection; </li></ul></ul><ul><li>Several commonly used methods defined by Type </li></ul><ul><ul><li>ConstructorInfo[ ] GetConstructors( ) </li></ul></ul><ul><ul><li>EventInfo[ ] GetEvents </li></ul></ul><ul><ul><li>FieldInfo[ ] GetFields </li></ul></ul>
  • 78. <ul><ul><li>MemberInfo[ ] Getmembers() </li></ul></ul><ul><ul><li>MethodInfo[ ] GetMethods() </li></ul></ul><ul><ul><li>PropertyInfo[ ] GetProperties() </li></ul></ul>
  • 79. Example 1 Obtain class method link
  • 80. Example 2 Obtain class constructor link
  • 81. Example 3 Obtain Types from Assemblies link MyClass.cs Compile the MyClass.cs into a MyClass.dll, you need to 1. Locate the csc.exe, and set the path 2. csc /t:library MyClass.cs
  • 82.  
  • 83.  
  • 84. Example 4 How to create and use a DLL with MS Visual Studio .NET link Step 1
  • 85. No Main() 1 2 3
  • 86. Step 2 1 2
  • 87. 10. Pointer <ul><li>Enable C# to use C/C++ high-performance, </li></ul><ul><li>systems code </li></ul><ul><li>Code must be marked as unsafe </li></ul><ul><ul><li>unsafe code does not execute under the full </li></ul></ul><ul><ul><li>management of the CLR </li></ul></ul><ul><li>When a pointer points to a managed variable , </li></ul><ul><li>it must use fixed to prevented the variable </li></ul><ul><li>from being moved by the garbage collector . </li></ul>
  • 88. Example 1 link Simple pointer demo
  • 89. Right-click the mouse 1 2 3 4
  • 90. Example 2 Using fixed t should be fixed in one location while p was point to &t.num Managed object link
  • 91. 11. The object class <ul><li>base class of all C# classes </li></ul><ul><li>object is just another name for System.Object </li></ul><ul><li>used in Boxing & Unboxing </li></ul><ul><ul><li>Boxing : an object reference refers to a value type </li></ul></ul><ul><ul><li>Unboxing : retrieve a value from a object </li></ul></ul><ul><li>as a Generic Data type </li></ul>
  • 92. Example 1 Boxing and Unboxing link
  • 93. Example 2 object as a generic data type link
  • 94. 12. ref & out <ul><li>parameter passing </li></ul><ul><ul><li>Value Type : pass by value </li></ul></ul><ul><ul><li>Reference Type : pass by reference </li></ul></ul><ul><li>ref & out let you pass value type by reference </li></ul>
  • 95. Example 1 ref & out link
  • 96. Example 2 swap with ref link
  • 97. 13. Inheritance <ul><li>a derived class inherits all of the variables , methods , properties , and indexers defined by the base class and add its own unique elements. </li></ul><ul><li>Three major topics when using inheritance </li></ul><ul><ul><li>Data </li></ul></ul><ul><ul><li>Constructor </li></ul></ul><ul><ul><li>Methods </li></ul></ul><ul><li>Polymorphism </li></ul>
  • 98. Example 1 Access bass class’s private data through properties link
  • 99. Example 2 Calling Base Class Constructor link
  • 100.  
  • 101. Example 3 Inheritance and Name Hiding link
  • 102.  
  • 103. Example 4 Using base to access a hidden item link
  • 104. Example 5 Virtual Methods and Overriding (polymorphism and dynamic binding) link
  • 105.  
  • 106.  
  • 107. Example 6 Using sealed to prevent inheritance link
  • 108.  
  • 109. 14. Interface <ul><li>No data members </li></ul><ul><li>No constructors , destructors </li></ul><ul><li>Not allow static member </li></ul><ul><li>Class members have no implementation </li></ul><ul><li>Many classes can implement the same </li></ul><ul><li>interface </li></ul><ul><li>When a class implements an interface, the </li></ul><ul><li>class must implement the entire interface . </li></ul>
  • 110. <ul><li>Class can implement more than one inter- </li></ul><ul><li>face . The interfaces are separated with a </li></ul><ul><li>comma. </li></ul><ul><li>A class can inherit a base class and also </li></ul><ul><li>implement one or more interface. In this case, </li></ul><ul><li>the name of the base class must come first . </li></ul><ul><li>The method that implement an interface must </li></ul><ul><li>be declared public . </li></ul><ul><li>Interface can be inherited </li></ul>
  • 111. Example 1 Interface Properties link
  • 112. Example 2 Interface Indexers link
  • 113.  
  • 114. Example 3 Interface can be inherited link
  • 115. Example 4 Interface Polymorphism link
  • 116. 15. Structures <ul><li>A structure is similar to a class, but it is of </li></ul><ul><li>value type . </li></ul><ul><li>cannot inherit or be a base for other struc- </li></ul><ul><li>tures or class (but it inherit object ) </li></ul><ul><li>can implement one or more interface </li></ul><ul><li>can define constructors, but not destructors </li></ul>
  • 117. <ul><li>However, you cannot define a default const- </li></ul><ul><li>ructor (no parameters) </li></ul><ul><li>can be created using new or performed the in- </li></ul><ul><li>itialization manually. </li></ul><ul><li>a struct was accessed directly, not through </li></ul><ul><li>reference variable, so it saved space and got </li></ul><ul><li>more efficiency . </li></ul>
  • 118. Example 1 Structure Demo link
  • 119.  
  • 120. Programming with C# and .NET .NET Remoting
  • 121. Outline <ul><li>Introduction </li></ul><ul><li>Basic Architecture </li></ul><ul><li>Examples </li></ul>2 3 1 4 Conclusion
  • 122. Introduction
  • 123. 1. Basic Model Proxy Formatter Client Channel Remote Object Formatter Server Channel Client Server 2 3 4 5 6 7 8 1 9
  • 124. 2. Calling Procedure Client Side client called the 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 . The messages are serialized using a formatter class , and are sent into a client channel . 1 2 3 4
  • 125. Server Side The server channel sends the serialized data to a formatter . The formatter deserialized the message . The client channel communicates with the server channel to transfer the message across the network . 5 6 7 8 The deserialized messages are then dispatched to the remote object .
  • 126. 3. Configuration Option Well-known Remote Objct Singleton SingleCall Client-activated
  • 127. Binary Formatter SOAP HTTP Channel TCP
  • 128. 4. Related Technology 1 2 3 DCOM Java RMI CORBA
  • 129. Architecture & Examples
  • 130. Architecture Overview <ul><li>Remote Objects </li></ul><ul><ul><li>Well-known : SingleCall vs. Singleton </li></ul></ul><ul><ul><li>Client-activated </li></ul></ul><ul><li>Activation </li></ul><ul><ul><li>Server-activated object (SAO) </li></ul></ul><ul><ul><li>Client-activated object (CAO) </li></ul></ul><ul><li>Channel </li></ul><ul><ul><li>TCP </li></ul></ul><ul><ul><li>HTTP </li></ul></ul>
  • 131. <ul><li>Formatter </li></ul><ul><ul><li>Binary </li></ul></ul><ul><ul><li>SOAP </li></ul></ul><ul><li>Proxy </li></ul><ul><ul><li>Transparent </li></ul></ul><ul><ul><li>Real </li></ul></ul><ul><li>Marshaling </li></ul><ul><ul><li>Marshal-by-value (MBV) </li></ul></ul><ul><ul><li>Marshal-by-reference (MBR) </li></ul></ul>
  • 132. <ul><li>Lease-Base Lifetime </li></ul><ul><ul><li>lease.RenewOnCallTime </li></ul></ul><ul><ul><li>sponsor.RenewalTime </li></ul></ul><ul><li>Lease machanism is for long-lived objects </li></ul><ul><li>Well-known singleton </li></ul><ul><li>Client-activated </li></ul>SingleCall types do not participate in the lifetime lease system.
  • 133. 1. SingleCall Remote object Remote object Remote object Client Server
  • 134. Did not cause the server to create a remote object each method call caused the server to create a new remote object
  • 135. Server ??
  • 136. <ul><li>Every remote method call will create a </li></ul><ul><li>new remote object on the server </li></ul><ul><li>SingleCall types do not participate in the </li></ul><ul><li>lifetime lease system </li></ul><ul><li>remote objects will automatically be </li></ul><ul><li>garbage collected after the call complete </li></ul><ul><li>useful when objects are required to do a </li></ul><ul><li>finite amount of work </li></ul>
  • 137. Example 1 programmatic configuration link
  • 138. Assembly Endpoint
  • 139.  
  • 140. Example 2 with configuration file link
  • 141.  
  • 142.  
  • 143.  
  • 144.  
  • 145. 2. Singleton Remote object Client Server
  • 146. Did not cause the server to create a remote object A remote object was created for the first method call. All of the clients will share the same remote object.
  • 147. Server
  • 148. <ul><li>The first remote method call will create a </li></ul><ul><li>remote object on the server </li></ul><ul><li>Multiple clients be serviced by only one </li></ul><ul><li>remote object </li></ul><ul><li>be careful about the concurrency and data </li></ul><ul><li>protection problem </li></ul><ul><li>use lease-based lifetime mechanism </li></ul>
  • 149. 3. Client-activated Remote object Client Server
  • 150. Cause the server to create a remote object Did not create any more remote object
  • 151. Server
  • 152. Example 1 programmatic configuration link
  • 153.  
  • 154. RemoteObject Constructor Argument
  • 155. Example 2 with configuration file link
  • 156.  
  • 157.  
  • 158.  
  • 159.  
  • 160. 4. Lease-Based Lifetime <ul><li>Long-lived remote objects use lease </li></ul><ul><li>machanism for their objects lifetime </li></ul><ul><li>Two ways to extend the lifetime </li></ul><ul><ul><li>Clients make remote method calls </li></ul></ul><ul><ul><li>use a sponsor </li></ul></ul><ul><li>When the leasing time is expired , the sponsor </li></ul><ul><li>is asked if it extends the lease. </li></ul>
  • 161. <ul><li>A value is defined with RenewOnCallTime </li></ul><ul><li>to extend the leasing time when client calls </li></ul><ul><li>the method of the remote object </li></ul><ul><li>The ISponsor interface defines the method </li></ul><ul><li>Renewal( ) </li></ul><ul><li>The class ClientSponsor provides a default </li></ul><ul><li>implementation for ISponsor interface. </li></ul>
  • 162. Remote object Client Server RenewOnCallTime CurrentLeaseTime If (CurrentLeaseTime >= RenewOnCallTime) {//Do nothing} else {CurrentLeaseTime= RenewOnCallTime;}
  • 163. Remote object Client Server Leasing time expired Cause a exception Client-activated
  • 164.  
  • 165. Client Server Leasing time expired Remote object Create a new remote object Remote object Well-known singleton
  • 166.  
  • 167. Example 1 CAO lease.RenewOnCallTime link
  • 168. Example 2 sponsor link
  • 169.  
  • 170. 5. Marshal-By-Value a Client Server a
  • 171. <ul><li>Marshaling means converting the object in </li></ul><ul><li>order to send it across the network (or </li></ul><ul><li>across processes or application domains) </li></ul><ul><li>With MBV the object is serialized into the </li></ul><ul><li>channel, and a copy of the object is created </li></ul><ul><li>on the other side of the network </li></ul><ul><li>The class must be marked with the attribute </li></ul><ul><li>[Serializable] </li></ul>
  • 172. Example 1 return object with MBV link
  • 173.  
  • 174. Client side
  • 175. 6. Marshal-By-Reference Client Server a proxy
  • 176. <ul><li>MBR creates a proxy on the client that is </li></ul><ul><li>used to communicate with the remote </li></ul><ul><li>object </li></ul><ul><li>The class must derived from </li></ul><ul><li>MarshalByRefObject </li></ul>
  • 177. Example 1 return object with MBR link
  • 178.  
  • 179. Server side
  • 180. Conclusion
  • 181. Conclusion .NET Remoting is built on a layered model, with each layer replaceable by custom code created by a developer. Therefore, new messaging, transport, and communication protocols can be implemented and plugged in as needed. Thus we can apply it to our distributed or web service system with least difficulties and at the same time have higher performance or interoperability than other technology can provide.

×