Remoting Configuration using VB.NET: Part 2

In this article I will explain you about VB.NET Remoting Configuration.
  • 1651

See Part 1
We have used a template for the <channels> element. How is this beneficial? The id attribute in the <channel> element provides a label that can be referred to in the <application> section. Notice, also, the template is outside the body of the <application>. The <channel> tag attribute ref is the link to channel information. This allows us to create a common file for both the server and the client. In the example in Listing 25.22, the template is in the same file, but in the real world, the scenario would likely be in the format shown in Listings 25.23 and 25.24.

Listing 25.23: The Common Template Configuration File


<?
xml version="1.0" ?>
<
configuration>
          <
system.runtime.remoting>
                   <
channels>
                             <
channel id="Http Server"
                            
name="Server Activated"
                            
type="System.Runtime.Remoting.Channels.Http.HttpServerChannel, System.Runtime.Remoting"/>
                   </
channels>
          </
system.runtime.remoting>
</
configuration>

Listing 25.24: The Server's Configuration File


<?
xml version="1.0" ?>
<
configuration>
          <
system.runtime.remoting>
                   <
application name="ServerActivatedServerExe">
                             <
service>
                                      <
wellknown
                                     
mode="SingleCall"
                                     
type="SimpleObjectLib.SimpleObject, SimpleObjectLib"
                                     
objectUri="Simple">
                                      </
wellknown>
                             </
service>
                             <
channels>
                                      <
channel ref="Http Server" port="1234"/>
                             </
channels>
                   </
application>
          </
system.runtime.remoting>
</
configuration>

To access these two files is simply a matter of calling as follows:

RemotingConfiguration.Configure( template configuration file name)
and
RemotingConfiguration.Configure( server's configuration file name)

RemotingConfiguration reads the directives in the template and applies them to the <application> segment whenever it encounters a ref attribute. The usefulness of this approach will become evident when configuring custom channel sink providers, discussed later in the coming article.

Server-activated objects (Listing 25.24) are distinguished from client-activated objects by the <activated> element's corresponding tag <wellknown>. The <wellknown> element's attributes mode, type, and objectUri mirror the parameters in earlier source code. It should be apparent that this is a server configuration file from the <service> tag.

The examples in this chapter were initially coded using Visual Studio .NET Beta2. RemotingConfiguration.Configure behaves differently in the release candidate. Listing 25.22 executed as expected in Beta2, loading the remoting DLL located in the global assembly cache (GAC). The release candidate, however, threw a "File Not Found" exception. This was unexpected behavior for an assembly in the GAC. To overcome this, highlight the remoting DLL and change Copy Local in properties to true.



Figure-2.gif

The client configuration file for server-activated objects differs only slightly from the clientactivated configuration (see Listing 25.25).

Listing 25.25: ServerActivatedClientExe.exe.config


<?
xml version="1.0" ?>
<
configuration>
          <
system.runtime.remoting>
                   <
application name="ServerActivatedClientExe">
                             <
client url="http://localhost:1234/Simple">
                                      <
wellknown
                                     
type="SimpleObjectLib.SimpleObject, SimpleObjectLib"
                                     
url="http://localhost:1234/Simple">
                                      </
wellknown>
                             </
client>
                             <
channels>
                                      <
channel ref="Http Client"/>
                             </
channels>
                   </
application>
          </
system.runtime.remoting>
</
configuration>

The <wellknown> tag contains the ever-present type attribute. The additional url attribute seems redundant because of the <client> element url attribute. Don't be misled. The <wellknown> element's url attribute is mandatory, whereas in this case the <client> element's url is optional.

Conclusion

Hope this article would have helped you in understanding VB.NET Remoting Configuration.

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.