Understanding SAO and CAO Activation Methods in .NET Remoting
page 7 of 9
by Abhishek Kumar Singh
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 40786/ 72

Creating metadata of server object for CAO specific client

1. Go to the Visual Studio command prompt. In my computer it is as:

D:\Program Files\Microsoft Visual Studio 8\SDK\v2.0>.

Move to the assembly folder of the project in the command prompt as given below for my sample.

D:\Program Files\Microsoft Visual Studio 8\SDK\v2.0>cd D:\RemoteServer\RemoteServer\bin\Release

2. Execute soapsuds.exe command with the parameter as given below.

D:\Program Files\Microsoft Visual Studio 8\SDK\v2.0>soapsuds -ia:RemoteServer -nowp -oa:Remote_Server_metadata.dll

Details:

* Soapsuds.exe: It is a tool provided in Microsoft .Net Framework to create a metadata (proxy) of server object (service).

* ia: An option to set with soapsuds.exe to specify the assembly for which metadata is to be generated. The assembly name extension (.dll or .exe) does not require mentioning here.

* RemoteServer: The server assembly name used in this article’s example. Replace it with yours.

* nowp: To specify, not to create, wrapped proxy.

* oa: To specify the target file name (metadata file).

* Remote_Server_metadata.dll: Target file name used for article’s example. Replace it with your suitable name.

Figure 1: Using soapsuds.exe at .Net SDK command prompt to create server metadata

After a successful execution of command you would see two new files in the Release directory as shown in the figure.

Figure 2: Metadata files of server after executing soapsuds.exe

You can go through the options for soapsuds in detail on MSDN.

In the client application add reference to the metadata DLL.

Figure 3: Adding server metadata file into the client application

CAO using Activator.CreateInstance()

Listing 7: ClientService.vb implementation using Activator.CreateInstance() which uses metadata referenced file to establish remote connection and call remote method in CAO mechanism

Imports System.Data
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Http
 
Public Class ClientService
 
    Private m_oTmrSend As System.Threading.Timer
    Private m_oRemote As RemoteServer.Server
    Private oChannel As HttpChannel = Nothing
    Private m_iTimeInterval As Integer
 
    Public Sub OnStart()
 
        oChannel = New HttpChannel(0)
        ChannelServices.RegisterChannel(oChannel, False)
        Dim url() = {New System.Runtime.Remoting.Activation.UrlAttribute( _
              "http://localhost:1/TestServerForCAOClient")}
        Try
            m_oRemote = CType( _
              Activator.CreateInstance(GetType(RemoteServer.Server), Nothing, url), _
            RemoteServer.Server)
 
            Console.WriteLine(" Remote Client Started at " & Now.ToString())
 
            Console.WriteLine("CLIENT_A :: Channel Registered :" & _
              oChannel.ChannelName)
            Dim timerDelegate As Threading.TimerCallback = AddressOf DoAction
            m_oTmrSend = New System.Threading.Timer(timerDelegate, Me, 0, 10000)
        Catch ex As Exception
            Console.WriteLine(ex.ToString())
            Console.Read()
        End Try
    End Sub
    Public Sub DoAction(ByVal sender As Object)
        Console.WriteLine("Received from Server: " & _
          m_oRemote.GetServerMessage("Client_A"))
    End Sub
 
    Protected Overrides Sub Finalize()
        MyBase.Finalize()
        ChannelServices.UnregisterChannel(oChannel)
        Console.WriteLine("CLIENT_A :: Channel Unregistered :: " & Now.ToString())
    End Sub
End Class

CAO using new operator

We can implement client class using new to create server object in CAO as given below.

Listing 8: ClientService.vb implementation by using new to create CAO object

Imports System.Data
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Http
 
Public Class ClientService
 
    Private m_oTmrSend As System.Threading.Timer
    Private m_oRemote As RemoteServer.Server
    Private oChannel As HttpChannel = Nothing
    Private m_iTimeInterval As Integer
 
    Public Sub OnStart()
 
        oChannel = New HttpChannel(0)
        ChannelServices.RegisterChannel(oChannel, False)
       Try
            RemotingConfiguration.RegisterActivatedClientType( _
        GetType(RemoteServer.Server), "http://localhost:1/TestServerForCAOClient")
            m_oRemote = New RemoteServer.Server
           
            Console.WriteLine(" Remote Client Started at " & Now.ToString())
 
            Console.WriteLine("CLIENT_A :: Channel Registered :" & _
              oChannel.ChannelName)
            Dim timerDelegate As Threading.TimerCallback = AddressOf DoAction
            m_oTmrSend = New System.Threading.Timer(timerDelegate, Me, 0, 10000)
        Catch ex As Exception
            Console.WriteLine(ex.ToString())
            Console.Read()
        End Try
    End Sub
 
 
    Public Sub DoAction(ByVal sender As Object)
        Console.WriteLine("Received from Server: " & _
          m_oRemote.GetServerMessage("Client_A"))
    End Sub
 
    Protected Overrides Sub Finalize()
        MyBase.Finalize()
        ChannelServices.UnregisterChannel(oChannel)
        Console.WriteLine("CLIENT_A :: Channel Unregistered :: " & Now.ToString())
 
    End Sub
End Class

View Entire Article

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-25 4:22:59 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search