Home SmartChannels Advanced scenarios: callbacks and authorization. - Client implementation.

Login Form



Advanced scenarios: callbacks and authorization.
Advanced scenarios: callbacks and authorization. - Client implementation. PDF Print E-mail
Article Index
Advanced scenarios: callbacks and authorization.
Callback interface definition.
Service interface definition.
Service implemetation.
Defining service configuration.
Client implementation.
Defining client configuration.
Enabling authorization.

Client implementation.

Ok. Since we have finished with the service and are able to run it, let's implement and configure our client to finally test our callback architecture.

  • Create new console application project in Visual Studio and name it "MyClient":

9

  • Add reference to IProgressObserver.dll
  • Add reference to SmartChannels.dll
  • For both libraries det "Copy local" option to "True"
  • Add reference to System.Configuration assembly.

You should get picture in solution explorer similar to the follow (do not forget to enable option “show all files”):

10

  • Add SmartChannels library license file to the project and rename it (the same way as you did for MyServer):
    • Right-click on the project in Solution Explorer window.
    • Select Add->Existing Item...
    • For non-commercial license select SmartChannels.lic file:
    • Rename it to match template .SmartChannels.lic
    • Change Copy to Output Directory property of MyClient.exe.SmartChannels.lic file to "Copy always" value.
  • Put this code inside Module1.vb of MyClient project:

Imports System
Imports System.Configuration
Imports System.Runtime.Remoting
 
Friend Class CallbackReceiver
    Inherits MarshalByRefObject
    Implements IProgressObserver.IProgressSubscriber
 
    Public Sub ProgressChanged(ByVal percent As Integer, ByVal message As String) Implements IProgressObserver.IProgressSubscriber.ProgressChanged
        Console.WriteLine("{0}% {1}", percent, message)
    End Sub
 
    'Since we manage the lifetime of the CallbackReceiver object by ourself, we override InitializeLifetimeService
    'and return Nothing telling remoting infrastructure not to include this object into
    'distributed garbage collector infrastructure
    Public Overrides Function InitializeLifetimeService() As Object
        Return Nothing
    End Function
End Class
 
Module Module1
    Const serverIP As String = "localhost"
 
    Sub Main()
        Try
            Try
                Dim fname As String = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).FilePath
                RemotingConfiguration.Configure(fname, False)
            Catch ex As Exception
                Console.WriteLine("Client. Error during Remoting configuration. Exception message:" & ex.Message)
                Exit Sub
            End Try
 
            Dim server As IProgressObserver.IMyService = CType(Activator.GetObject(GetType(IProgressObserver.IMyService), _
            "tcp://" + serverIP + ":5000/MyService.rem"), IProgressObserver.IMyService)
 
            Console.WriteLine("Calling service.")
            server.DoJob(New CallbackReceiver())
        Catch ex As Exception
            Console.WriteLine("Client. Unexpected error. Exception message:" & ex.Message)
        End Try
        Console.WriteLine("Press Enter to exit...")
        Console.ReadLine()
    End Sub
End Module

 

Ok.  We have almost done with the client. Now it is time to define client remoting configuration.

 



 

Copyright © 2010 SmartSoftwareBits.com. All Rights Reserved.