Home SmartChannels Advanced scenarios: callbacks and authorization. - Service implemetation.

Login Form



Advanced scenarios: callbacks and authorization.
Advanced scenarios: callbacks and authorization. - Service implemetation. 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.

Service implemetation.

Ok. We are ready to implement service functionality.

  • Create new console application project in Visual Studio and call it MyService:
2

 

  • Add reference to IProgressObserver.dll (server interface definition).
  • Add reference to SmartChannels.dll library.
  • For both libraries set “Copy Local” options 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”):

3

  • Add SmartChannels library license file to the project and rename it:
  • Right-click on the project in Solution Explorer window.
  • Select Add->Existing Item…

4

  • For non-commercial license select SmartChannels.lic file:

5

  • Rename it to match template .SmartChannels.lic

6

  • Change Copy to Output Directory property of MyService.exe.SmartChannels.lic file to “Copy always” value:

7

  • Put this code inside Module1.vb of MyService project:

Imports System
Imports System.Configuration
Imports System.Runtime.Remoting
Imports System.Globalization
 
Module Module1
    Sub Main()
        Try
            Dim fname As String = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).FilePath
            RemotingConfiguration.Configure(fname, False)
        Catch ex As Exception
            Console.WriteLine("Server. Can not start.")
            Console.WriteLine("Server. Error during Remoting configuration. Exception message:" & ex.Message)
        End Try
        Console.WriteLine("Press Enter to exit...")
        Console.ReadLine()
    End Sub
End Module 
 
Friend Class MyService
    Inherits MarshalByRefObject
    Implements IProgressObserver.IMyService
 
    Public Sub DoJob(ByVal progressCallback As IProgressObserver.IProgressSubscriber) _
     Implements IProgressObserver.IMyService.DoJob
        If progressCallback Is Nothing Then
            Throw New ArgumentNullException("progressCallback")
        End If
        Dim numberOfSteps As Integer = 5
        'Go step by step,
        'Emulate some work - sleep for 2 seconds on every step
        'Then report progress to the caller
        For stepNo As Integer = 1 To 5
            'Emulate some work - sleep for 2 seconds on every step
            Threading.Thread.Sleep(2000)
            'Report progress to the caller
            Try
                progressCallback.ProgressChanged(CType(stepNo * 100 / numberOfSteps, Integer),  String.Format(CultureInfo.InvariantCulture, "Step {0} of {1} completed.", stepNo, numberOfSteps))
            Catch ex As Exception
                'We caught an exception on remote caller notification
                'We may ignore exception and continue or
                'we may abort execution and rethrow.
                'Here we just ignore it (we do not care much since we marked the callback
                'method with OneWay attribute) and continue.
            End Try
        Next
        'Ok. We have finished the job.
    End Sub
End Class


We are almost done with the service. All we need to do also – is to define network configuration for the service through app.config file.

 



 

Copyright © 2010 SmartSoftwareBits.com. All Rights Reserved.