.NET REMOTING IN ACTION in Visual Basic .NET

Print Quick Response Code in Visual Basic .NET .NET REMOTING IN ACTION

CHAPTER 3 .NET REMOTING IN ACTION
Quick Response Code Encoder In VB.NET
Using Barcode drawer for .NET framework Control to generate, create Denso QR Bar Code image in VS .NET applications.
www.OnBarcode.com
Scanning Denso QR Bar Code In VB.NET
Using Barcode decoder for Visual Studio .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
HttpChannel chnl = new HttpChannel(1234); ChannelServices.RegisterChannel(chnl); RemotingConfiguration.RegisterWellKnownServiceType( typeof(MyRemoteObject), "MyRemoteObject.soap", WellKnownObjectMode.Singleton); // the server will keep running until keypress. Console.ReadLine(); } } When the client is started, the output will show a behavior consistent with the normal object-oriented way of thinking; the value that is returned is the same value you set two lines before (see Figure 3-3).
PDF-417 2d Barcode Generator In Visual Basic .NET
Using Barcode generator for .NET Control to generate, create PDF-417 2d barcode image in VS .NET applications.
www.OnBarcode.com
Barcode Creator In VB.NET
Using Barcode creation for Visual Studio .NET Control to generate, create Barcode image in .NET applications.
www.OnBarcode.com
Figure 3-3. Client s output for a Singleton object
Code 39 Maker In VB.NET
Using Barcode maker for .NET Control to generate, create Code 39 Extended image in VS .NET applications.
www.OnBarcode.com
GTIN - 13 Drawer In Visual Basic .NET
Using Barcode creation for Visual Studio .NET Control to generate, create European Article Number 13 image in .NET applications.
www.OnBarcode.com
The same is true for the server, as Figure 3-4 shows.
Generating Barcode In VB.NET
Using Barcode printer for .NET framework Control to generate, create Barcode image in .NET applications.
www.OnBarcode.com
Make OneCode In Visual Basic .NET
Using Barcode creator for Visual Studio .NET Control to generate, create USPS OneCode Solution Barcode image in .NET applications.
www.OnBarcode.com
Figure 3-4. Server s output for a Singleton object
Drawing QR Code JIS X 0510 In Visual Studio .NET
Using Barcode generation for VS .NET Control to generate, create Denso QR Bar Code image in .NET applications.
www.OnBarcode.com
Painting QR Code ISO/IEC18004 In Visual Studio .NET
Using Barcode printer for ASP.NET Control to generate, create QR image in ASP.NET applications.
www.OnBarcode.com
CHAPTER 3 .NET REMOTING IN ACTION
Making Code 39 Extended In .NET Framework
Using Barcode generation for ASP.NET Control to generate, create USS Code 39 image in ASP.NET applications.
www.OnBarcode.com
Generate Code 128 Code Set B In Objective-C
Using Barcode drawer for iPhone Control to generate, create Code-128 image in iPhone applications.
www.OnBarcode.com
An interesting thing happens when a second client is started afterwards. This client will receive a value of 42 directly after startup without your setting this value beforehand (see Figures 3-5 and 3-6). This is because only one instance exists at the server, and the instance will stay alive even after the first client is disconnected.
Make Code 3 Of 9 In Java
Using Barcode generator for Java Control to generate, create Code 3/9 image in Java applications.
www.OnBarcode.com
PDF 417 Decoder In Visual Basic .NET
Using Barcode recognizer for VS .NET Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
Use Singletons when you want to share data or resources between clients. But always keep in mind Tip that more than one client might access the same object at any given time, so you have to write the serverside code in a thread-safe way.
UPC Symbol Creator In Java
Using Barcode drawer for Android Control to generate, create UPC A image in Android applications.
www.OnBarcode.com
UPC Symbol Recognizer In None
Using Barcode reader for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
Figure 3-5. The second client s output when calling a Singleton object
Scan QR Code In Java
Using Barcode recognizer for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
Barcode Creator In Visual Studio .NET
Using Barcode printer for Reporting Service Control to generate, create Barcode image in Reporting Service applications.
www.OnBarcode.com
Figure 3-6. Server s output after the second call to a SingleCall object
Scanning Code 3/9 In Visual Basic .NET
Using Barcode scanner for .NET Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
EAN13 Drawer In C#
Using Barcode generator for .NET Control to generate, create UPC - 13 image in VS .NET applications.
www.OnBarcode.com
Published Objects When using either SingleCall or Singleton objects, the necessary instances will be created dynamically during a client s request. When you want to publish a certain object instance that s been precreated on the server for example, one using a nondefault constructor neither alternative provides you with a solution. In this case you can use RemotingServices.Marshal() to publish a given instance that behaves like a Singleton afterwards. The only difference is that the object has to already exist at the server before publication. YourObject obj = new YourObject(<your params for constr>); RemotingServices.Marshal(obj,"YourUrl.soap");
CHAPTER 3 .NET REMOTING IN ACTION
The code in the ServerStartup class will look like this: class ServerStartup { static void Main(string[] args) { Console.WriteLine ("ServerStartup.Main(): Server started"); HttpChannel chnl = new HttpChannel(1234); ChannelServices.RegisterChannel(chnl); MyRemoteObject obj = new MyRemoteObject(4711); RemotingServices.Marshal(obj,"MyRemoteObject.soap"); // the server will keep running until keypress. Console.ReadLine(); } } When the client is run, you can safely expect to get a value of 4711 on the first request because you started the server with this initial value (see Figures 3-7 and 3-8).
Figure 3-7. Client s output when calling a published object
Figure 3-8. Server s output when publishing the object
CHAPTER 3 .NET REMOTING IN ACTION
Client-Activated Objects
A client-activated object (CAO) behaves mostly the same way as does a normal .NET object (or a COM object).1 When a creation request on the client is encountered (using Activator.CreateInstance() or the new operator), an activation message is sent to the server, where an instance of the specified class is created. The server then creates an ObjRef, which is used to uniquely identify this object and returns it to the client. On the client proxy, this ObjRef will be turned into a TransparentProxy, which points to the underlying server-side instance. A client-activated object s lifetime is managed by the same lifetime service used by SAOs, as shown later in this chapter. CAOs are so-called stateful objects; an instance variable that has been set by the client can be retrieved again and will contain the correct value. These objects will store state information from one method call to the other. CAOs are explicitly created by the client, so they can have distinct constructors like normal .NET objects do. Direct/Transparent Creation The .NET Remoting framework can be configured to allow client-activated objects to be created like normal objects using the new operator. Unfortunately, this manner of creation has one serious drawback: you cannot use shared interfaces or base classes. This means that you either have to ship the compiled objects to your clients or use SoapSuds to extract the metadata. This tool allows you to extract a metadata-only assembly out of a running server or a serverside implementation assembly. In the past two years, experience has taught me that relying on this tool is not a good choice for most applications. As of today, Microsoft suggests not to use it for .NET to .NET distributed applications. I will nevertheless demonstrate the use of SoapSuds.exe in case you are willing to take the risk.
Caution If you use the initial version 1.1 of the .NET Framework (without service packs), metadata generated by SoapSuds cannot be used for client-activated objects. This is a bug that has been detailed in article 823445 in the Microsoft Knowledge Base. You can find more details about this problem and how to contact Product Support Services (PSS) to obtain a hotfix at http://support.microsoft.com/ default.aspx scid=kb;en-us;823445.
In the following example, you ll use more or less the same class you did in the previous examples; it will provide your client with a SetValue() and GetValue() method to store and retrieve an int value as the object s state. The metadata that is needed for the client to create a reference to the CAO will be extracted with SoapSuds.exe, about which you ll read more later in this chapter. The reliance on SoapSuds allows you to develop the server application without any need for up-front design of a shared assembly, therefore the server will simply include the CAOs implementation. You can see this in Listing 3-4.
1. The only exception from this rule lies in the object s lifetime, which is managed completely differently from the way it is in .NET generally or in COM.
Copyright © OnBarcode.com . All rights reserved.