VB.NET Remoting Config File

matt1356

Member
Joined
Nov 30, 2006
Messages
5
Programming Experience
3-5
Hi,
Can someone please tell me how I would convert the code below to use a config file instead. I've looked at loads of examples on the web but can't quite get it to work:
VB.NET:
Imports System.Runtime.Remoting
Imports system.Runtime.Remoting.Channels
Public Class frmClient

    Private Server As IRemotingInterface.IRemoteInterface

    Private Sub cmdHelloWorld_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdHelloWorld.Click
        MessageBox.Show(Server.GetMessage)
    End Sub

    Private Sub InitRemoting()
        Dim Channel As Channels.Tcp.TcpChannel
        Dim serverProv As Channels.BinaryServerFormatterSinkProvider
        Dim clientProv As Channels.BinaryClientFormatterSinkProvider
        Dim props As IDictionary = New Hashtable
        serverProv = New Runtime.Remoting.Channels.BinaryServerFormatterSinkProvider
        clientProv = New Channels.BinaryClientFormatterSinkProvider
        serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full
        props("port") = 0
        Channel = New Channels.Tcp.TcpChannel(props, clientProv, serverProv)
        ChannelServices.RegisterChannel(Channel, False)
        Try
            Server = CType(Activator.GetObject(GetType(IRemotingInterface.IRemoteInterface), _
            "tcp://localhost:9000/RemotingExample"), IRemotingInterface.IRemoteInterface)
            If Server Is Nothing Then
                MsgBox("Unable to connect to remoting service!", MsgBoxStyle.Exclamation)
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub frmClient_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        InitRemoting()
    End Sub
End Class
I can't figure out how to instantiate the "server" variable using a config file so that MessageBox.Show(Server.GetMessage) doesn't throw an error....
Thanks
 
Last edited by a moderator:
Update

OK, this works on the client side:

Client Config file as follows:

HTML:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<client>
<wellknown
type="IRemotingInterface.IRemoteInterface, ANAliasName"
url="tcp://localhost:9000/RemotingExample"/>
</client>
<channels>
<channel ref="tcp" port="0">
<clientProviders>
<formatter ref="binary" />
</clientProviders>
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
</configuration>

Client Code as follows:

VB.NET:
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE][SIZE=2] frmClient[/SIZE]
 
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] Server [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] IRemotingInterface.IRemoteInterface[/SIZE]
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] cmdHelloWorld_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] cmdHelloWorld.Click[/SIZE]
[SIZE=2]MessageBox.Show(Server.GetMessage)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
 
 
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] InitRemoting()[/SIZE]
[SIZE=2]RemotingConfiguration.Configure([/SIZE][SIZE=2][COLOR=#800000]"client.exe.config"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]Server = [/SIZE][SIZE=2][COLOR=#0000ff]CType[/COLOR][/SIZE][SIZE=2](Activator.GetObject([/SIZE][SIZE=2][COLOR=#0000ff]GetType[/COLOR][/SIZE][SIZE=2](IRemotingInterface.IRemoteInterface), _[/SIZE]
[SIZE=2][COLOR=#800000]"tcp://localhost:9000/RemotingExample"[/COLOR][/SIZE][SIZE=2]), IRemotingInterface.IRemoteInterface)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] frmClient_Load([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Load[/SIZE]
[SIZE=2]InitRemoting()[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE]

BUT this doesn't work on the server side:

Server Config file as follows:

HTML:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<client>
<wellknown
type="IRemotingInterface.IRemoteInterface, ANAliasName"
url="tcp://localhost:9000/RemotingExample"/>
</client>
<channels>
<channel ref="tcp" port="0">
<clientProviders>
<formatter ref="binary" />
</clientProviders>
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
</configuration>

Server code as follows:

VB.NET:
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE][SIZE=2][COLOR=#000000] frmServer[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] [COLOR=black]frmServer_Load[/COLOR]([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] [COLOR=black]sender[/COLOR] [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE]
[SIZE=2][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2][COLOR=#000000] server [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#000000] IRemoteInterface[/COLOR][/SIZE]
[SIZE=2][COLOR=black]RemotingConfiguration.Configure([/COLOR][/SIZE][SIZE=2][COLOR=black]"Server.exe.config"[/COLOR][/SIZE][SIZE=2][COLOR=black],[/COLOR] [/SIZE][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE][SIZE=2])[/SIZE]
 
[SIZE=2][SIZE=2][COLOR=black]server =[/COLOR] [/SIZE][SIZE=2][COLOR=#0000ff]CType[/COLOR][/SIZE][SIZE=2]([COLOR=black]Activator.GetObject[/COLOR]([/SIZE][SIZE=2][COLOR=#0000ff]GetType[/COLOR][/SIZE][SIZE=2]([COLOR=black]IRemoteInterface[/COLOR]), _[/SIZE]
[SIZE=2][COLOR=#800000]"tcp://localhost:9000/RemotingExample"[/COLOR][/SIZE][SIZE=2]), [COLOR=black]IRemotingInterface.IRemoteInterface[/COLOR])[/SIZE]
[/SIZE][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[/COLOR][/SIZE]

I get the error message "Could not load file or assembly 'ANAliasName' or one of its dependencies."

Please help as I have wasted hours on this. I just can't get the server to work with a config file!!!

Thanks
 
Here is .NET Framework Remoting Overview - It includes a beginner walkthrough building a remoting set. (click the link 'Building a Basic .NET Framework Remoting Application') See how to host app is setup. Your server config is missing the service section.
 
Back
Top