ARTICLE

Call Contexts in VB.NET

Posted by Manish Tewatia Articles | Visual Basic Language September 29, 2010
In this article I will explain you about Call Contexts in VB.NET.
 
Reader Level:

The CallContext class can be thought of as "out-of-band" data or a channel hook. It operates at a thread level within an application domain. To cross application domain boundaries, objects must derive from the System.Runtime.Remoting.Messaging.ILogicalThreadAffinative interface, see Listing 25.18. An object registers with CallContext using the "key/value" paradigm. It is hooked to each method call and is part of IMessage, the _CallContext entry, which is sent over the wire. Using CallContext is simply a matter of calling the static methods SetData() and GetData().

There is a standard library (CallContextLib) and two console applications (CallContextServer and CallContextClient) after creating these two console applications you need to create a application named RemoteContextInfo it is the class that will contain the out-of-band data. Here I will given the example of  RemoteContextInfo class and when you use this class with CallContextServer and CallContextClient application the output which is produced is given in Figures 25.13 and 25.14 are the client and server output, respectively.

Listing 25.18: RemoteContextInfo.vb


<Serializable()> _
Public Class RemoteContextInfo
    Implements ILogicalThreadAffinative
    Private m_machineName As String = Nothing
    Private m_clientDir As String = Nothing
    Public Sub New() 
        m_machineName = Environment.MachineName
        m_clientDir = Environment.CurrentDirectory
    End Sub
    Public ReadOnly Property MachineName() As String
 
        Get
            Return (m_machineName)
        End Get
    End Property
    Public ReadOnly Property ClientDir() As String
        Get
            Return (m_clientDir)
        End Get
    End Property
End Class

To get and set the call context data, simply use the following code:

        Dim data As RemoteContextInfo = Nothing
       
data = New RemoteContextInfo()
        CallContext.SetData("Client", data)
        Dim data As RemoteContextInfo = DirectCast(CallContext.GetData("Client"), RemoteContextInfo)

Figure 25.13: Client Output

Figure-25.13.gif

Figure 25.14: Server Output

Figure-25.14.gif

This is an ideal way for custom proxies or message sinks to pass information from the client to the server or vice versa, without intruding into the functionality of the application.

Conclusion

Hope this article would have helped you in understanding Call Contexts in VB.NET.

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor