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.

Figure 12-3: How .<strong>NET</strong> Remot<strong>in</strong>g marshals objects by reference.The .<strong>NET</strong> Remot<strong>in</strong>g implementation of MBR provides <strong>for</strong> a proxy/stub pair and aphysical channel <strong>for</strong> network transportation. The proxy represents the remote object tothe client, as it simply mirrors the same set of methods and properties. Each client<strong>in</strong>vocation of a remote method actually hits the local proxy, which, <strong>in</strong> turn, takes care ofrout<strong>in</strong>g the call down to the server. A method <strong>in</strong>vocation orig<strong>in</strong>ates a message thattravels on top of a channel and a transmission protocol.Each message passes through a cha<strong>in</strong> of hook objects (called s<strong>in</strong>ks) on each side ofthe transport channel. S<strong>in</strong>ks are nearly identical to W<strong>in</strong>dows hooks. By def<strong>in</strong><strong>in</strong>g andregister<strong>in</strong>g a s<strong>in</strong>k, the programmer can per<strong>for</strong>m a specific operation at a specific stageof the remot<strong>in</strong>g process. Because the creation of the proxy takes place automatically,the programmer has little to do other than creat<strong>in</strong>g an <strong>in</strong>stance of the target object andissu<strong>in</strong>g the call.If the object resides <strong>in</strong> an external AppDoma<strong>in</strong>, the remot<strong>in</strong>g <strong>in</strong>frastructure creates alocal proxy <strong>for</strong> it to per<strong>for</strong>m the requested operation. But how can the code determ<strong>in</strong>ewhether a given object is local, lives <strong>in</strong> a remote AppDoma<strong>in</strong>, or just doesn't exist? Inspite of the sophisticated code that constitutes the remot<strong>in</strong>g <strong>in</strong>frastructure,programm<strong>in</strong>g remote objects is mostly a matter of setup. Once the client has beenproperly configured, you normally create a new <strong>in</strong>stance of the remote class us<strong>in</strong>g thenew operator, no matter what type of class you're call<strong>in</strong>g and where it resides. Clientsmust declare to the CLR which classes are remote and provide connection <strong>in</strong><strong>for</strong>mation.Remote objects, <strong>in</strong> turn, must be publicly available and bound to a given channel.The MarshalByRefObject ClassInherit<strong>in</strong>g from the MarshalByRefObject class is the key that enables user classes to beaccessed across AppDoma<strong>in</strong> boundaries <strong>in</strong> applications that support remot<strong>in</strong>g.MarshalByRefObject is the base class <strong>for</strong> objects that communicate acrossAppDoma<strong>in</strong>s. Serializable classes that do not <strong>in</strong>herit from MarshalByRefObject, when<strong>in</strong>stantiated from a remote assembly, are implicitly marshaled by value. Other classesare simply considered nonremotable.So if you want to write a remote component that uses the network efficiently and alwaysruns on the server, the only th<strong>in</strong>g you have to do is create the class <strong>in</strong>herit<strong>in</strong>g fromMarshalByRefObject, as follows:public class Northw<strong>in</strong>dService : MarshalByRefObject430

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

Saved successfully!

Ooh no, something went wrong!