ARTICLE

Singleton Objects with SOAP using VB.NET

Posted by Manish Tewatia Articles | Visual Basic Language October 01, 2010
In this article I will explain you about Singleton Objects with SOAP using VB.NET.
 
Reader Level:

As you learn in my previous article the term singleton is a concept where a global object services all requests. The Singleton concept is a taken from Design Patterns. It is similar to CWinApp in Microsoft Foundation Classes-the one and only application object. Although there can be many printers in a system, there should be only one printer spooler. There should be only one file system and one window manager.

Now we talk about Singleton Objects with SOAP, there are two well-known object modes in SOAP .NET Remoting:

  • SingleCall: Every message is dispatched to a new object instance.

  • Singleton: Every message is dispatched to the same object instance.

Listing 23.12 displays the sample server code.

Listing 23.12: SOAP Server2 (Listing23.12.vb)


// compile with:
// csc /r:object2.dll Listing23.12.vb
/* sample output:
press <enter> to exit
DateTime server activated

Counter: 1
Hi Clown Bozo. Here is the current DateTime: 8/19/2002 4:02:28 AM

Counter: 2
Hi Clown Bozo. Here is the current DateTime: 8/19/2002 4:02:28 AM

Counter: 3
Hi Clown Bozo. Here is the current DateTime: 8/19/2002 4:02:28 AM

Counter: 4
Hi Clown Bozo. Here is the current DateTime: 8/19/2002 4:02:28 AM

Counter: 5
Hi Clown Bozo. Here is the current DateTime: 8/19/2002 4:02:28 AM

Counter: 6
Hi Clown Bozo. Here is the current DateTime: 8/19/2002 4:02:28 AM

Counter: 7
Hi Clown Bozo. Here is the current DateTime: 8/19/2002 4:02:28 AM

Counter: 8
Hi Clown Bozo. Here is the current DateTime: 8/19/2002 4:02:28 AM

Counter: 9
Hi Clown Bozo. Here is the current DateTime: 8/19/2002 4:02:28 AM

Counter: 10
Hi Clown Bozo. Here is the current DateTime: 8/19/2002 4:02:28 AM
DateTime server Object Destroyed
*/
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Http 
Namespace ExampleRemoting
    Public Class Example
        Public Shared Sub Main()
            ChannelServices.RegisterChannel(New HttpChannel(999))
            RemotingConfiguration.RegisterWellKnownServiceType(Type.[GetType
            ("ExampleRemoting.DateTimeServer, object2"), "server/SayDateTime.SOAP",
            WellKnownObjectMode.Singleton)
            System.Console.WriteLine("press <enter> to exit.")
            System.Console.ReadLine()
        End Sub
    End Class
End Namespace

Listing 23.13 shows the sample client code. Note that we will use HTTP channels to connect to the remote object twice in a row.

Listing 23.13: SOAP Client2 (Listing23.13.vb)


/* after executing the Listing23.12.exe use the SOAPSUDS tool to create object2.dll
proxy:
soapsuds -url:http://127.0.0.1:999/server/SayDateTime.SOAP?WSDL -oa:object22.dll
*/
// compile with:
// csc /r:object22.dll Listing23.13.vb
/* sample output:
HttpChannel

1 - HttpChannel
Hi Clown Bozo. Here is the current DateTime: 8/19/2002 4:02:28 AM

2 - HttpChannel
Hi Clown Bozo. Here is the current DateTime: 8/19/2002 4:02:28 AM

3 - HttpChannel
Hi Clown Bozo. Here is the current DateTime: 8/19/2002 4:02:28 AM

4 - HttpChannel
Hi Clown Bozo. Here is the current DateTime: 8/19/2002 4:02:28 AM

5 - HttpChannel
Hi Clown Bozo. Here is the current DateTime: 8/19/2002 4:02:28 AM
HttpChannel

6 - HttpChannel
Hi Clown Bozo. Here is the current DateTime: 8/19/2002 4:02:28 AM

7 - HttpChannel
Hi Clown Bozo. Here is the current DateTime: 8/19/2002 4:02:28 AM

8 - HttpChannel
Hi Clown Bozo. Here is the current DateTime: 8/19/2002 4:02:28 AM

9 - HttpChannel
Hi Clown Bozo. Here is the current DateTime: 8/19/2002 4:02:28 AM

10 - HttpChannel
Hi Clown Bozo. Here is the current DateTime: 8/19/2002 4:02:28 AM
*/

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)
            Run()
            ' run 1st, singleton counter counts
            Run()
            ' run 2nd, singleton counter counts
        End Sub
 
        Public Shared Sub Run()
            Console.WriteLine("HttpChannel.")
            Dim obj As DateTimeServer = DirectCast(Activator.GetObject(GetType(DateTimeServer),
                "http://127.0.0.1:999/server/SayDateTime.SOAP"), DateTimeServer)
            For i As Integer = 0 To 4
                Console.WriteLine(obj.BeniSay() & " - HttpChannel")
                Console.WriteLine(obj.MyMethod("Clown Bozo"))
            Next
        End Sub
    End Class
End Namespace

Conclusion

Hope this article would have helped you in understanding Singleton Objects with SOAP using VB.NET.

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • 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.
    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.
Team Foundation Server Hosting
Become a Sponsor