13.07.2015 Views

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

S<strong>in</strong>gleCall ObjectsA well-known type declared as a S<strong>in</strong>gleCall object has a new <strong>in</strong>stance of it createdwhenever a request arrives. The host application creates a new <strong>in</strong>stance of theS<strong>in</strong>gleCall object, executes the requested method, and then routes any return valuesback to the client. After that, the object goes out of scope and is left to the garbagecollector.Although it's not completely impossible, preserv<strong>in</strong>g state from one call to the next isrealistically a bit impractical <strong>for</strong> S<strong>in</strong>gleCall objects. In this case, the lifetime of the object<strong>in</strong>stance is extremely short and barely covers the duration of the method call. You cantry either stor<strong>in</strong>g <strong>in</strong><strong>for</strong>mation <strong>in</strong> a database (or any sort of persistent storage medium) orpark<strong>in</strong>g data <strong>in</strong> other objects with a different lifetime scheme.Client-Side ActivationClient-activated objects are <strong>in</strong>stantiated on the client as the result of a call to the newoperator or to the System.Activator object. Each remot<strong>in</strong>g client runs its own copy of theobject and can control it at will. For example, the client can use any of the availableconstructors. In addition, persist<strong>in</strong>g the state dur<strong>in</strong>g the session is straight<strong>for</strong>ward anddoes not require any special cod<strong>in</strong>g. On the down side, shar<strong>in</strong>g state between clients isdifficult, and to do so, you must resort to a database, a disk file, or any other globalobject <strong>in</strong> the current AppDoma<strong>in</strong>.The follow<strong>in</strong>g code snippet shows how to change the contents of the tag toreflect a client-activated object. Instead of the tag, you use the tag. This tag supports only the type attribute. No object URI is necessarywith client-activated objects. More precisely, the URI is still necessary, but because theactivation occurs on the client and at a very specific moment <strong>in</strong> time, the URI can besilently generated by the .<strong>NET</strong> Remot<strong>in</strong>g <strong>in</strong>frastructure and attached to each call.As with S<strong>in</strong>gleton objects, the lifetime of a client-activated object is controlled by theLM. The <strong>in</strong>stance of the object rema<strong>in</strong>s active until the proxy is destroyed.Choos<strong>in</strong>g the Activation Mode That FitsTheoretically, all the work<strong>in</strong>g modes exam<strong>in</strong>ed up to now don't affect <strong>in</strong> any shape orfashion the way <strong>in</strong> which you code your remotable classes. For example, a clientactivatedobject is <strong>in</strong> no way different from a S<strong>in</strong>gleton object. All options can be setdeclaratively and, aga<strong>in</strong> speak<strong>in</strong>g theoretically, each object can be configured to work<strong>in</strong> different ways simply by chang<strong>in</strong>g a few entries <strong>in</strong> the server's configuration file.Intrigu<strong>in</strong>g as this possibility is, such flexibility is not realistic <strong>in</strong> practice because a realworldobject might want to exploit <strong>in</strong> depth the specific features of a work<strong>in</strong>g mode. Inother words, you should thoughtfully and carefully choose the configuration options <strong>for</strong>your remote object and then stick to that configuration as long as the user'srequirements are stable. For example, if you determ<strong>in</strong>e that the S<strong>in</strong>gleton mode isappropriate <strong>for</strong> your component, you will probably want to implement an <strong>in</strong>ternal statemanagement eng<strong>in</strong>e to share some variables. When at a later time you decide to setthe object to work—say, <strong>in</strong> S<strong>in</strong>gleCall mode—the state management eng<strong>in</strong>e issomewhat useless.Let's analyze our ServiceSalesProvider class to determ<strong>in</strong>e the most appropriateoptions. To beg<strong>in</strong>, the object needs to query a back-end database (Northw<strong>in</strong>d). Even445

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!