Remoting questions

N

Nak

Hi there,

I have been messing around with remoting in an attempt to create a
"shared application" as mentioned in another thread by that name.

I have created a singleton object just like the example in the 101
VB.NET examples. It works great, only 1 instance ever gets created and is
shared by each client. I have a few questions though,

* Can the singleton contain events? In such a way that when the
event is raised each application consuming the singleton recieves the event?
I had troubles trying to implement this.

* Can the host consume the singleton? I didn't seem to be able to
make the host instantiate an instance of the singleton so that it contained
the first and only instance for monitoring purposes etc.

Thanks for your help :) I'm sure I'm doing something wrong maybe :-\

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
T

Tom Shelton

First, I want to qualify and say that I'm not a great expert on this
subject.
Hi there,

I have been messing around with remoting in an attempt to create a
"shared application" as mentioned in another thread by that name.

I have created a singleton object just like the example in the 101
VB.NET examples. It works great, only 1 instance ever gets created and is
shared by each client. I have a few questions though,

* Can the singleton contain events? In such a way that when the
event is raised each application consuming the singleton recieves the event?
I had troubles trying to implement this.

Yes - but you need to be aware of thread blocking issues... There is a
very good book on the subject by Ingo Rammer "Advanced .NET Remoting",
there is both a C# and a VB.NET version of the book. Anyway, you may
want to check out this link for the threading issue:

http://www.ingorammer.com/RemotingFAQ/HANDLING_EVENTS_HANGS_APPLICATION.html

* Can the host consume the singleton? I didn't seem to be able to
make the host instantiate an instance of the singleton so that it contained
the first and only instance for monitoring purposes etc.

I'm not sure... But, I don't see why not.

HTH
 
N

Nak

Hi there,
First, I want to qualify and say that I'm not a great expert on this

Fine by me, any advice is greatly appreciated!
Yes - but you need to be aware of thread blocking issues... There is a
very good book on the subject by Ingo Rammer "Advanced .NET Remoting",
there is both a C# and a VB.NET version of the book. Anyway, you may
want to check out this link for the threading issue:
http://www.ingorammer.com/RemotingFAQ/HANDLING_EVENTS_HANGS_APPLICATION.html

I shall check the link out, thanks loads.
I'm not sure... But, I don't see why not.

Yeah, I thought it might be, I just don't know the correct method for doing
so. Hopefully the above link will shed some light on the subject.

Thanks for your help again :)

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
P

Peter Huang [MSFT]

Hi Nak,

I am researching the issue, I will update you with new information ASAP.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
 
N

Nak

Hi there,
I am researching the issue, I will update you with new information ASAP.

Excellent I shall eagerly await your reply. I'm also out to buy the
advanced .net remoting book to give that a whirl :) Thanks for your help.

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
P

Peter Huang [MSFT]

Hi Nick,
* Can the singleton contain events? In such a way that when the
event is raised each application consuming the singleton recieves the event?
I had troubles trying to implement this.
Here is a sample about the sink event in remoting object.
Remoting Events
http://staff.develop.com/woodring/dotnet/

* Can the host consume the singleton? I didn't seem to be able to
make the host instantiate an instance of the singleton so that it contained
the first and only instance for monitoring purposes etc.

Yes, here I write a simple sample for you.
[Server Host]
Imports System
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp
Imports ClassLibrary5
Module Module1
Sub Main()
Dim tcpchannel As New TcpChannel(8082)
ChannelServices.RegisterChannel(tcpchannel)

RemotingConfiguration.RegisterWellKnownServiceType(GetType(HelloServiceClass
), "RemoteTest", WellKnownObjectMode.Singleton)
Dim service As HelloServiceClass =
CType(Activator.GetObject(GetType(HelloServiceClass),
"tcp://localhost:8082/RemoteTest"), HelloServiceClass)
Console.WriteLine(service.HelloMethod("Server"))
Console.ReadLine()
End Sub
End Module

[Remoting Object]
Imports System
Public Class HelloServiceClass
Inherits MarshalByRefObject
Private str As String
Public Sub New()
Console.WriteLine("Constructor")
End Sub
Public Property ObjFlag()
Get
ObjFlag = str
End Get
Set(ByVal Value)
str = ObjFlag
End Set
End Property
Public Function HelloMethod(ByVal name As String) As String
Return "Hi there " + name + "."
End Function
End Class

[Client]
Imports System
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Activation
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp
Imports ClassLibrary5
Module Module1
Sub Main()
ChannelServices.RegisterChannel(New TcpChannel)
Dim sc As ClassLibrary5.HelloServiceClass
sc = CType(Activator.GetObject(GetType(HelloServiceClass),
"tcp://localhost:8082/RemoteTest"), HelloServiceClass)
Console.WriteLine(sc.HelloMethod("Client"))
End Sub
End Module

From the sample , you will find that he constructor of the remoting object
is called once.
Did I misunderstand your meaning?
If you have any related question, please feel free to let me know.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
From: "Nak" <[email protected]>
References: <OqU#[email protected]>
<[email protected]>
 
N

Nak

Hi Peter,

Excuse me, but this is very difficult to explain...

I have been looking at the example thoroughly, unfortunately it is in C#, so
I am a little unsure on a few minor details.

Firstly, the events are raised via the eventShim class, unfortunately I
can't for the life of me see 1 solid reference to the eventshim class in the
code!! So I am slightly confused as to how the server could possibly use
the class to forward events when it doesn't even have a reference to or know
about the class.

I would have thought that the server would create a singleton of the
eventshim class and use that to forward to all registered clients, but the
server doesn't even use it! The eventshim class is instantiated on the
client rather than the server.

For example, the server creates a new class, this class is exposed as a
remoting object. The class implements the interface desired for the
remoting object, which in-turn exposes the event. In my code I know that
the server is attempting to raise the event, as I have placed a messagebox
just before the line, but unfortunately the event never gets to the client!!

I suppose my main question should be, where should the eventshim class be
created? Is it simply used on the client side to recieve events? If that
is the case then how does the event even get there if it is not even linked
to the remoteable object? Very confusing example, and seeing as I am using
VB.NET Standard I cannot even see if it works as I would expect. Thanks for
your help again, I think I might scrap that one and read the advanced .net
remoting book.

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
P

Peter Huang [MSFT]

Hi Nak,

There is a simple VB remoting event sample in .NET SDK.
e.g.
D:\Program Files\Microsoft Visual Studio .NET
2003\SDK\v1.1\Samples\Technologies\Remoting\VB
I also has comments in line.

If you have any related question please feel free to let me know.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
From: "Nak" <[email protected]>
References: <OqU#[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
Subject: Re: Remoting questions
Date: Tue, 21 Oct 2003 14:05:09 +0100
Lines: 44
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: dsl213-218-228-203.as15444.net 213.218.228.203
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:148643
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

Hi Peter,


Excuse me, but this is very difficult to explain...

I have been looking at the example thoroughly, unfortunately it is in C#, so
I am a little unsure on a few minor details.

Firstly, the events are raised via the eventShim class, unfortunately I
can't for the life of me see 1 solid reference to the eventshim class in the
code!! So I am slightly confused as to how the server could possibly use
the class to forward events when it doesn't even have a reference to or know
about the class.

EventShim is in the calcif.cs i.e. calcif.dll
You can see the calcif.dll will be referenced in both the server and client.

I would have thought that the server would create a singleton of the
eventshim class and use that to forward to all registered clients, but the
server doesn't even use it! The eventshim class is instantiated on the
client rather than the server.

You may try to see the app.config file of the server.
What the configure file do can also be done in the code.

Remoting Settings Schema
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/ht
ml/gnconremotingsettingsschema.asp

<!-- server.exe.config -->
<configuration>
<system.runtime.remoting>
<application name="calcsrv">
<service>
<wellknown mode="Singleton" type="Calc, server" objectUri="calc" />
</service>
<channels>
<channel ref="http" port="999">
<clientProviders>
<formatter ref="binary" />
</clientProviders>
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full"/> <!-- On the
1.1 runtime, add typeFilterLevel='Full' to the formatter element -->
</serverProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
</configuration>


For example, the server creates a new class, this class is exposed as a
remoting object. The class implements the interface desired for the
remoting object, which in-turn exposes the event. In my code I know that
the server is attempting to raise the event, as I have placed a messagebox
just before the line, but unfortunately the event never gets to the client!!
Event is a kind of call back mechanism.
static void Main()
{
RemotingConfiguration.Configure("client.exe.config");

ICalc c = (ICalc)
RemotingServices.Connect(typeof(ICalc),
ConfigurationSettings.AppSettings["calcURL"]);

MagicNumberCallback cb = EventShim.Create(new
MagicNumberCallback(OnMagicNumber));
c.MagicNumber += cb;//add event handle

Console.WriteLine("c.AppDomainName (Calc) = {0}", c.AppDomainName);
Console.WriteLine("2 + 2 (Calc) = {0}", c.add(2, 2));
//Server fire the MagicNumber event
//Client get the event and fire the event handle function OnMagicNumber

Console.WriteLine("4 + 4 (Calc) = {0}", c.add(4, 4));

c.MagicNumber -= cb;
}


I suppose my main question should be, where should the eventshim class be
created?
Server side.
Is it simply used on the client side to recieve events? If that
It is an remoting object with event declared.
is the case then how does the event even get there if it is not even linked
to the remoteable object? Very confusing example, and seeing as I am using
VB.NET Standard I cannot even see if it works as I would expect. Thanks for
your help again, I think I might scrap that one and read the advanced .net
remoting book.
That is a good book, I think that book will give your many information.

If you have any related question, please feel free to let me know.
 
N

Nak

Hi Peter,
D:\Program Files\Microsoft Visual Studio .NET
2003\SDK\v1.1\Samples\Technologies\Remoting\VB
I also has comments in line.

Aaah, I see I have the same for v1.0, I shall check it out, excellent thank
you :)

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
P

Peter Huang [MSFT]

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top