12.12 Control Versioning for Remote Objects


Problem

You want to create a component host that can host more than one version of the same object.

Solution

Install all versions of the object into the GAC, and explicitly register each version at a different URI endpoint.

Discussion

.NET Remoting doesn't include any intrinsic support for versioning. When a client creates a remote object, the component host automatically uses the version in the local directory or, in the case of a shared assembly, the latest version from the GAC. To support multiple versions, you have three choices:

  • Create separate component host applications. Each component host will have a different version of the remote object assembly and will register its version with a different URI. This approach forces you to run multiple component host applications at once and is most practical if you are using IIS hosting (as described in recipe 12.9).

  • Create an entirely new remote object assembly (instead of simply changing the version). You can then register the classes from both assemblies at different URIs, using the same component host.

  • Install all versions of the remote object assembly in the GAC. You can now create a component host that maps different URIs to specific versions of the remote object assembly.

The last option is the most flexible in cases where you need to support multiple versions. For example, consider the following configuration file, which registers two versions of the RemoteObjects assembly at two different endpoints. Notice that you need to include the exact version number and public key token when using assemblies from the GAC. You can find this information by viewing the assembly in the Windows Explorer GAC plug-in (browse to C:\[WindowsDir]\Assembly).

 <configuration>   <system.runtime.remoting>     <application>       <service>         <!-- The type information is split over two lines to accommodate the              bounds of the page. In the configuration file, this information              must all be placed on a single line. -->         <wellknown mode="SingleCall"           type="RemoteObjects.RemoteObject, RemoteObjects, Version 1.0.0.1,                 Culture=neutral, PublicKeyToken=8b5ed84fd25209e1"           objectUri="RemoteObj" />         <wellknown mode="SingleCall"           type="RemoteObjects.RemoteObject, RemoteObjects, Version 2.0.0.1,                  Culture=neutral, PublicKeyToken=8b5ed84fd25209e1"           objectUri="RemoteObj_2.0" />       </service>       <channels>         <channel ref="tcp server" port="9080" />       </channels>     </application>   </system.runtime.remoting> </configuration> 

The client configuration file won't change at all (aside from updating the URI, if required). The client "chooses" the version it wants to use by using the corresponding URI.




C# Programmer[ap]s Cookbook
C# Programmer[ap]s Cookbook
ISBN: 735619301
EAN: N/A
Year: 2006
Pages: 266

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