Sunny
7/22/2004 2:43:00 PM
Hi,
In article <u$q$wQ8bEHA.996@TK2MSFTNGP12.phx.gbl>, blahhh@blahhhhh.com
says...
> I'm totally new to remoting and panicking.
> I've 2 winforms applications. The client has to ask the server for a
> database record asynchronously. Some time later the server returns the
> response with data for the record.
> I've found lots of simple examples on the net but they all seem to be for
> pure single server/client classes of type MarshalByRefObject in console mode
> and I can't seem to find out what to do( and where to do it ) if I want to
> add something similar to my winform application.
All examples are console apps, because it's easier to write and debug,
and shorter to publish. All of them contain at least 2 parts: the MBR
object and the channel and object registration. Nothing stops you to put
the channel and object registration in a windows form where it is
suitable for you - Main method, in Load event handler, in a button event
handler, etc. As in the server app you need to register the channels and
the object only once, most probably you want to do it in the Main
method. For the client, you may want to register the channel on demand.
Just make sure you do it only once, or you release and unregister the
channel before next registration. So you can put this code wherever it
is best for you.
>
> Secondly,
> I'm generally worried about this server port allocation where ports are
> selected with no particular skill.
> I'm assuming each application registers a port number for it's sole use.
> So if all applications eventually go .net, then is it expected there'll be
> exceptions flying as duplications happen?
>
Server port is static. I.e. you have to predefine it so it is known for
the clients. There is no way the client to guess where and how to
connect. Maybe you are confused reading lines like this:
channel = new TcpChannel(0), and because in the docs you read that it
chooses a random free port.
This code is usually used at the client. It creates basically 2
channels. One server and one client channel. The client channel does not
have port, because it is used to connect to the server on a wellknown
port. And the so called "server" channel at the client side, the system
chooses for you any free port, so you do not need to worry if any other
application on your machine uses any hardcoded port you may try to use
manually. So, this channel is only used for callbacks from the server,
I.e. when you want to provide a way the server to call back the client
(like rising an event, etc.). This port is used only for the current
connection and only by the server. And the client knows how to notify
the server for its callback port.
Sunny