Web proxy server - CHAPTER 18 604 THE .NET REMOTING LAYER

CHAPTER 18 604 THE .NET REMOTING LAYER Source Code The AsyncWKOCarProviderClient project is located under the Chapter 18 subdirectory. The Role of the [OneWay] Attribute Imagine that your CarProvider has a new method named AddCar(), which takes a JamesBondCar input parameter and returns nothing. The key point is that it returns nothing. As you might assume given the name of the System.Runtime.Remoting.Messaging.OneWayAttribute class, the .NET remoting layer passes the call to the remote one-way method, but does not bother to set up the infrastructure used to return a given value (hence the name one-way). Here is the update: // Home of the [OneWay] attribute. using System.Runtime.Remoting.Messaging; … namespace CarGeneralAsm { public class CarProvider : MarshalByRefObject { … // The client can ‘fire and forget’ when calling this method. [OneWay] public void AddCar(JamesBondCar newJBC) { theJBCars.Add(newJBC);} } } Callers would invoke this method directly as always: // Make the car provider. CarProvider cp = new CarProvider(); // Add a new car. cp.AddCar(new JamesBondCar(”Zippy”, 200, false, false)); From the client s point of view, the call to AddCar() is completely asynchronous, as the CLR will ensure that a background thread is used to remotely trigger the method. Given that AddCar() has been decorated with the [OneWay] attribute, the client is unable to obtain any return value from the call. Because AddCar() returns void, this is not an issue. In addition to this restriction, also be aware that if you have a [OneWay] method that defines output or reference parameters (via the out or ref keyword), the caller will not be able to obtain the callee s modification(s). Furthermore, if the [OneWay] method happens to throw an exception (of any type), the caller is completely oblivious of this fact. In a nutshell, remote objects can mark select methods as [OneWay] to allow the caller to employ a fire-and-forget mentality. Summary In this chapter, you examined how to configure distinct .NET assemblies to share types between application boundaries. As you have seen, a remote object may be configured as an MBV or MBR type. This choice ultimately controls how a remote type is realized in the client s application domain (a copy or transparent proxy). If you have configured a type to function as an MBR entity, you are suddenly faced with a number of related choices (WKO versus CAO, single call versus singleton, and so forth), each of which was addressed during this chapter. As well, you examined the process of tracking the lifetime of a remote object via the use of leases and lease sponsorship. Finally, you revisited of the role of the .NET delegate type to understand how to asynchronously invoke a remote method (which, as luck would have it, is identical to the process of asynchronously invoking a local type).
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

Leave a Reply