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.
--------------------
<
[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.