SingleCall Objects

SingleCall Objects

The preceding example uses a client-activated type because its behavior closely resembles that of an ordinary, in-process object. Remoting also provides two types of server-activated (or "well-known") objects, which the client must connect to using the specified URL. The first type is SingleCall.

SingleCall objects are the most efficient and common type of remotable object in an enterprise application because they are extremely lightweight and efficient. With a SingleCall object, the object is created at the beginning of every method invocation and released at the end. This ensures that valuable server memory is never retained for long. The client retains a reference to the proxy for the object as long as it wants, and the proxy creates the remote object with each call. If any defaults need to be set, they can be initialized in the class constructor, which will be executed with every call as the object is re-created.

In the simple example used so far, the remote object doesn't retain any state, so it's a perfect choice for a SingleCall object. You would need to modify the server configuration file as shown in Listing 4-14.

Listing 4-14 A component host that provides a SingleCall object
 <configuration>    <system.runtime.remoting>       <application name="SimpleServer">          <service>             <wellknown mode="SingleCall"                        type="RemoteObjects.RemoteObject, RemoteObjects"                        objectUri="RemoteObject" />          </service>          <channels>             <channel ref="tcp server" port="8080" />          </channels>       </application>    </system.runtime.remoting> </configuration> 

Notice that the <activated> tag has been replaced with a <wellknown> tag and an objectURI has been added to uniquely identify the server-side object. The channel information doesn't need to change. Next you can update the client configuration file to use the <wellknown> tag and objectURI, as shown in Listing 4-15.

Listing 4-15 A client that uses a SingleCall object
 <configuration>    <system.runtime.remoting>       <application name="SimpleClient">          <client url>             <wellknown                     type="RemoteObjects.RemoteObject, RemoteObjects"                     url="tcp://localhost:8080/SimpleServer/RemoteObject"/>          </client>          <channels>             <channel ref="tcp client"/>          </channels>       </application>    </system.runtime.remoting> </configuration> 

Service provider components are ideal for SingleCall objects over .NET Remoting. On the other hand, an object that requires a resource that is expensive to retrieve should not be SingleCall. Suppose, for example, that you create a server-side object that reads a large quantity of data from a database and provides aggregate information to the client. (You might use a design like this if clients are connecting over a slow Internet connection and the amount of raw data is extremely large.) In this case, you need to use a client-activated or singleton object so that the data can be retained; otherwise, the remote object would need to requery the database with each method call.



Microsoft. NET Distributed Applications(c) Integrating XML Web Services and. NET Remoting
MicrosoftВ® .NET Distributed Applications: Integrating XML Web Services and .NET Remoting (Pro-Developer)
ISBN: 0735619336
EAN: 2147483647
Year: 2005
Pages: 174

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net