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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Figure 12-4: The SalesReport virtual directory created to make the remotable objectaccessible.If you choose IIS as the activation agent, you must be aware of a few th<strong>in</strong>gs. IIS canlisten only to the http channel; any other channel you <strong>in</strong>dicate is simply ignored. Theway IIS applies the <strong>in</strong><strong>for</strong>mation read from the web.config file is hard-coded and can't beprogrammatically controlled or changed. However, you can create a global.asax file <strong>in</strong>the virtual folder, hook the Application_Start event, and then execute some customcode. In addition, the <strong>in</strong>evitable use of SOAP as the underly<strong>in</strong>g protocol <strong>in</strong>creases theaverage size of network packets.NoteAs often happens, the use of IIS as the activation agent has prosand cons. You don't need to write any extra code, but you lose a bit<strong>in</strong> flexibility. Rega<strong>in</strong><strong>in</strong>g the lost flexibility is still possible, but at theprice of writ<strong>in</strong>g nontrivial code. For example, you can write anApplication_Start event handler and apply extra b<strong>in</strong>ary <strong>for</strong>matters atboth ends of the http channel. In this way, the SOAP packets willconta<strong>in</strong> b<strong>in</strong>ary data and you'll save some bytes.Us<strong>in</strong>g IIS as the activation agent is natural when you plan to expose the same remoteservice through .<strong>NET</strong> Remot<strong>in</strong>g and Web services. So let's assume <strong>in</strong> our exampleapplication that IIS is the activation agent and SalesReport is the virtual directory.Activation PoliciesIn addition to the remotable object's identity, channels, and ports, the serverconfiguration file also conta<strong>in</strong>s another important piece of <strong>in</strong><strong>for</strong>mation—the objectactivation policy. An MBR remotable object can be either server-activated or clientactivated.Server-activated objects are created by the server only when the client<strong>in</strong>vokes the first method through the local proxy. Client-activated objects are created onthe server as soon as the client <strong>in</strong>stantiates the object us<strong>in</strong>g either the new operator ormethods of the System.Activator class.In addition, server-activated objects can be declared as S<strong>in</strong>gleton or S<strong>in</strong>gleCall objects.A S<strong>in</strong>gleton object has exactly one <strong>in</strong>stance to serve all possible clients. A S<strong>in</strong>gleCallobject, on the other hand, requires that each <strong>in</strong>com<strong>in</strong>g call is served by a new <strong>in</strong>stanceof the remotable object. A remotable object declares its required activation policy <strong>in</strong> theconfiguration file through specific subtrees placed below the node.Server-Side ActivationServer-activated objects are remotable objects whose entire life cycle is directlycontrolled by the host application. Server-activated objects are <strong>in</strong>stantiated on the441

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

Saved successfully!

Ooh no, something went wrong!