Getting started: sample .NET client-server application with SmartChannels.
|
Getting started: sample .NET client-server application with SmartChannels. - Server implementation |
|
|
|
|
Page 2 of 5
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:

- 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”):

- Add SmartChannels library license file to the project and rename it:
- 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 <YouExecutableNameWithExtention>.SmartChannels.lic
-
- Change Copy to Output Directory property of MyServer.exe.SmartChannels.lic file to “Copy always” value:
- 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.
|