dotnet remoting:
I am trying to create a system that will execute a method (in the
host environment) on an object passed to it via remoting. The object
should be created on the client side, passed MBV style to the host
where the host will execute the function defined in the interface. The
code below probably shows what I'm trying to do much better. As you
can imagine, it doesn't work; the exception thrown is shown under the
offending line of the client code.
Two questions:
1) How can I pass the objects that implement ICommandExecutable to the
host by value so that they run in the host's App Domain?
2) Is there a better way of accomplishing what I'm trying to do? Some
requirements of the problem are:
-- There could potentially be hundred's of "hosts" with the "client"
creating and pushing out commands for each of them to execute.
-- The commands may change frequently so the hosts can't know the
details of all possible commands and I cannot update or change the
host's code each time I add, edit, or remove executable commands.
Editing and changing the client is acceptable.
Any help would be greatly appreciated.
Thanks
=============================================================
=============================================================
RemoteCommand Library:
Public Class Executioner
Inherits MarshalByRefObject
Public Sub New()
End Sub
Public Function execute(ByVal command As ICommandExecutable) As
String
Return command.run()
End Function
End Class
'''''''''''''''''''''''''''''''''''
Public Interface ICommandExecutable
Function run() As String
End Interface
=============================================================
=============================================================
The Host (Module and app.config)
Imports System.Runtime.Remoting
Module Module1
Sub Main()
RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile,
False)
Console.Write("Press <enter> to exit")
Console.Read()
End Sub
End Module
'''''''''''''''''''''''''''''''''''''
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<service>
<wellknown mode="SingleCall"
objectUri="Executioner.rem"
type="RemoteCommand.Executioner, RemoteCommand" />
</service>
<channels>
<channel ref="tcp" port="49341" />
</channels>
</application>
</system.runtime.remoting>
....
=============================================================
=============================================================
The Client (Client code, app.config, ThreadGetter Class)
(...)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile,
False)
End Sub
Private Sub btnRemoteThread_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnRemoteThread.Click
Dim ralf As New RemoteCommand.Executioner
txtRemoteThread.Text = ralf.execute(New ThreadGetter())
//**
Unable to find assembly 'myClient, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null'
**//
End Sub
(...)
'''''''''''''''''''''''''''''''''''''
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<client>
<wellknown mode="SingleCall"
type="RemoteCommand.Executioner, RemoteCommand"
url="tcp://localhost:49341/Executioner.rem" />
</client>
</application>
</system.runtime.remoting>
'''''''''''''''''''''''''''''''''''''
<Serializable()> _
Public Class ThreadGetter
Implements RemoteCommand.ICommandExecutable
Public Function run() As String Implements
RemoteCommand.ICommandExecutable.run
Return CStr(Threading.Thread.CurrentThread.ManagedThreadId)
End Function
End Class