> To be able to send commands to the service, I added .NET Remoting. The
> connection works fine and all that, but my trouble is how to pick up
> the serial COM object that was initialized when the service started.
> When the "SendCommand" function is called, a new instance of the
> SerialPort object is being made and all settings are lost. Please see
> the code below.
Since you need to maintain state, you need to marshal your object as a
singleton.
You'll also need to override the InitializeLifetimeService function:
http://www.thinktecture.com/Resources/RemotingFAQ/SINGLETON_IS_DYING.html
Jonah Olsson - 17 Apr 2006 10:28 GMT
Hi,
I'm using Singleton for the RemoteConnector class through the App.config
file, but do I need the ComService class to be Singleton as well? Here's my
.config:
<system.runtime.remoting>
<application name="RemoteConnector">
<service>
<wellknown mode="Singleton"
type="Scanmarket.ComTalker.RemoteConnector, ComTalker" objectUri="remcon" />
</service>
<channels>
<channel ref="http" port="999">
<clientProviders>
<formatter ref="binary" />
</clientProviders>
<serverProviders>
<formatter ref="binary" typeFilterLevel='Full' />
</serverProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
/Jonah
>> To be able to send commands to the service, I added .NET Remoting. The
>> connection works fine and all that, but my trouble is how to pick up
[quoted text clipped - 9 lines]
>
> http://www.thinktecture.com/Resources/RemotingFAQ/SINGLETON_IS_DYING.html
Jonah Olsson - 18 Apr 2006 18:39 GMT
Anyone?
/Jonah
Spam Catcher - 18 Apr 2006 23:58 GMT
"Jonah Olsson" <jonah@IHATESPAM.com> wrote in news:O$p7D8wYGHA.2208
@TK2MSFTNGP03.phx.gbl:
> Anyone?
>
> /Jonah
Did you read the article? You need to override the Lifetime of the object:
http://www.thinktecture.com/Resources/RemotingFAQ/SINGLETON_IS_DYING.html
Jonah Olsson - 19 Apr 2006 18:34 GMT
Thanks, but maybe I wasn't clear in my question. The
InitializeLifetimeService override is already in place. The problem was that
the object within the Windows Service class itself is lost. Maybe your
answer to Alberto could give me a clue.
Cheers,
Jonah
> "Jonah Olsson" <jonah@IHATESPAM.com> wrote in news:O$p7D8wYGHA.2208
> @TK2MSFTNGP03.phx.gbl:
[quoted text clipped - 6 lines]
>
> http://www.thinktecture.com/Resources/RemotingFAQ/SINGLETON_IS_DYING.html
Spam Catcher - 20 Apr 2006 00:49 GMT
> Thanks, but maybe I wasn't clear in my question. The
> InitializeLifetimeService override is already in place. The problem
> was that the object within the Windows Service class itself is lost.
Hmm I took a look at your code:
Public Sub SendCommand(ByVal cmd As String) Implements ICom.SendCommand
Dim cs As new ComService
cs.SendCommand(cmd)
End Sub
Declare CS as a class variable - don't reinstantiate it on each call. Won't
that fix your problem?
Also take a look at RemotingServices.Marshal command - that'll let you
marshal existing instances of objects.