Home SmartChannels Getting started: sample .NET client-server application with SmartChannels. - Server implementation

Login Form



Getting started: sample .NET client-server application with SmartChannels.
Getting started: sample .NET client-server application with SmartChannels. - Server implementation PDF Print E-mail
Article Index
Getting started: sample .NET client-server application with SmartChannels.
Server implementation
Defining server configuration
Client implementation
Defining client configuration

Server implementation.

Ok. It is time to implement server functionality. To make it easier let’s make the server a console application.
  • Create new console application project in Visual Studio and call it MyServer:
image003
  • Add reference to IMyServer.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”):
image005
  • Add SmartChannels library license file to the project and rename it:
    • Right-click on the project in Solution Explorer window.
    • Select Add->Existing Item…
image007
  •  
    • For non-commercial license select SmartChannels.lic file:
image009
  •  
    • Rename it to match template <YouExecutableNameWithExtention>.SmartChannels.lic
image011
  •  
    • Change Copy to Output Directory property of MyServer.exe.SmartChannels.lic file to “Copy always” value:
image013
  • Put this code inside Module1.vb of MyServer project:

Imports System
Imports System.Configuration
Imports System.Runtime.Remoting

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 MyServer
    Inherits MarshalByRefObject
    Implements IMyServer.IMyServer

    Public Sub LogMessage(ByVal message As String) Implements IMyServer.IMyServer.LogMessage
        If Not message Is Nothing Then
            Console.WriteLine(message)
        End If
    End Sub
End Class


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

 

Copyright © 2010 SmartSoftwareBits.com. All Rights Reserved.