Blue Theme Orange Theme Green Theme Red Theme
 
Team Foundation Server Hosting
Home | Forums | Videos | Photos | Blogs | Beginners | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Mindcracker MVP Summit 2012
Search :       Advanced Search »
Home » Visual Basic Language » Common Interfaces using VB.NET

Common Interfaces using VB.NET

In this article I will explain you about Common Interfaces using VB.NET.

Author Rank :
Page Views : 1135
Downloads : 0
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
Mindcracker MVP Summit 2012
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


Let's see another aspect of .NET Remoting. This will put you in mind of the COM+ style of remote object usage. We will develop an example using a shared interface. The interfaces also afford us a good means for using black-box objects. We have used this feature with type library (TLB) files with COM+ objects. To develop against a type library is sufficient to use services on a COM server. The client calls GetObject on an endpoint without knowing what the exact object type is; all it knows is that the object implements an interface. This illustrates how we can build a client that does not reference a server object at compile-time. The sample code for this example consists of four parts: a shared interface, the remote object that implements this interface, a server, and a client that will use this interface method via an unknown object. Listing 23.17 displays the code for the shared interface.

Listing 23.17: SOAP Shared Interface3 (Listing23.17.VB)

    Imports System
    Namespace ExampleRemoting
         
Public Interface IDateTime
               
Function DateTimeMethod(name As [String]) As String
         
End Interface
    End Namespace

Listing 23.18 contains the code for the object that implements the shared interface.

Listing 23.18: SOAP Object That Implements Share 3 (Listing23.18.VB)

    Namespace ExampleRemoting
        Public Class DateTimeServer
            Inherits MarshalByRefObject
            Implements IDateTime
            Public Sub New()
                Console.WriteLine("DateTime server activated")
            End Sub
            Protected Overrides Sub Finalize()
                Try
                    Console.WriteLine("DateTime server Object Destroyed")
                Finally
                    MyBase.Finalize()
                End Try
            End Sub
            Public Function DateTimeMethod(ByVal name As [String]) As [String]
                Dim strMessage As [String] = "Hi " + name + ". Here is the current DateTime: " + DateTime.Now
                Console.WriteLine(strMessage)
                Return strMessage
            End Function
        End Class
    End
Namespace

The code for the server that delivers the remote methods appears in Listing 23.19.

Listing 23.19: SOAP Server3 (Listing23.19.VB)

    Imports System
    Imports System.Runtime.Remoting
    Imports System.Runtime.Remoting.Channels
    Imports System.Runtime.Remoting.Channels.Http
    Namespace ExampleRemoting
        Public Class Example
            Public Shared Sub Main()
                Dim channel As New HttpChannel(8888)
                ChannelServices.RegisterChannel(channel)
                RemotingConfiguration.RegisterWellKnownServiceType(Type.[GetType]("ExampleRemoting.DateTimeServer, Object3"), "SayDateTime",
                WellKnownObjectMode.SingleCall)
                System.Console.WriteLine("press <enter> to exit.")
                System.Console.ReadLine()
            End Sub
        End Class
    End
Namespace

Listing 23.20 shows the code for the client that connects to the server and uses the methods exposed.

Listing 23.20: SOAP Client3 (Listing23.20.VB)

    Imports System
    Imports System
    Imports System.Runtime.Remoting
    Imports System.Runtime.Remoting.Channels
    Imports System.Runtime.Remoting.Channels.Http
    Namespace ExampleRemoting
        Public Class Client
            Public Shared Sub Main()
                Dim channel As New HttpChannel()
                ChannelServices.RegisterChannel(channel)
                ' create an object of type interface
                Dim obj As IDateTime = DirectCast(Activator.GetObject(GetType(ExampleRemoting.IDateTime), "http://127.0.0.1:8888/SayDateTime"), IDateTime)
                If obj = Nothing Then
                    Console.WriteLine("could not locate server!")
                Else
                    Console.WriteLine(obj.DateTimeMethod("Bozo the clown"))
                End If
            End Sub
        End Class
    End
Namespace
    Namespace ExampleRemoting
        Public Class Client
            Public Shared Sub Main()
                Dim channel As New HttpChannel()
                ChannelServices.RegisterChannel(channel)
                ' create an object of type interface
                Dim obj As IDateTime = DirectCast(Activator.GetObject(GetType(ExampleRemoting.IDateTime), "http://127.0.0.1:8888/SayDateTime"), IDateTime)
                If obj = Nothing Then
                    Console.WriteLine("could not locate server!")
                Else
                    Console.WriteLine(obj.DateTimeMethod("Bozo theclown"))
                End If
            End Sub
        End Class
    End
Namespace

Conclusion

Hope this article would have helped you in understanding Common Interfaces using VB.NET.

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Manish Tewatia
Manish is Very much interested in Microsoft & LifeStyle Accessory Designand working with Microsoft technologies. His expert areas are ASP.NET, ADO.NET, C# .NET, WPF, WCF, Windows Phone 7, Android, SQL Server, HTML , XAML, etc…
He is doing MCA and he love to drive fast bikes.
inspired from Mr. Mahesh Chand.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
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.
Dynamic PDF
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.
Discover the top 5 tips for understanding .NET
Ricky Leeks presents the top 5 tips for understanding .NET Interoperability. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
DevExpress Free UI Controls
Become a Sponsor
 Comments
DevExpress Free UI Controls
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.