Rob,
I tried following 2 ways based on your instruction, still doesn't work:
(Note: both client and server read from config file for intial Factory
object)
(Way 1) CLIENT side:
......
IRemoteFactory fact =
(IRemoteFactory)RemotingHelper.CreateProxy(typeof
(IRemoteFactory));
IRemoteObject iro = (IRemoteObject)Factory.CreateInstance();
IRemoteObject.GetValue;
SERVER side:
class RemoteObject : MarshalByReference, IRemoteObject
{
.....
}
classs RemoteFactory
{
.......
IRemoteObject CreateInstance()
{
AppDomain ad = AppDomain.CreateDomain("My second domain");
string portName = Guid.NewGuid().ToString();
ChannelServices.RegisterChannel(new IpcChannel(portName));
return ( (RemoteObject)ad.CreateInstanceAndUnWrap(....));
}
.......
}
Server side I got error says: The channel 'ipc' is already registered.
This is because in the server side configuration file, the initial
RemoteFactory object is registed by 'ipc'
(Way 2)CLIENT side:
no code change
SERVER side
add following line under "ChannelServices.RegisterChannel(new
IpcChannel(...))":
RemotingConfiguration.RegisterWellKnowServiceType(
typeof(RemoteObject), "RemoteObject.rem",
WellKnowObjectMode.Singleton);
the rest of the server code are same.
Server side I got the same error as in (1)
QUESTIONS:
(1)do I miss anything here, looks like I can't create second IPC channel in
server since the first one is already created in the server config file. the
server side config file looks like following
....
<application>
...
<service>
<wellknown type="General.RemoteFactory, MyFactoryAssemble"
objectUri="RemoteFactory.rem"
mode="Singleton" />
</service>
<channels>
<channel ref="ipc" portName="MyFirstPort" />
</channels>
...
</application>
....
client side has a corresponding config file.
(2)at client side, I don't know anything about RemoteObject with newly
created "protName" by server?
this might be a stupid question:
at client side do I need to register the RemoteObject with portName? if
yes how the server pass the created "portName" to client?
(3) since the RemoteObject instance(reference?) is created by second
appdomain, however the channel registration is still in the first domain,
could that be the problem?
Thanks!
Hang
[quoted text, click to view] "Robert Jordan" <robertj@gmx.net> wrote in message
news:dg3f3q$ef8$03$1@news.t-online.com...
>>> Thanks for the suggestion, however I won't be able to know how many
>>> clients
>>> will connect to the server, so the number of domains can't be determined
>>> in
>>> advance. In other words, the domains need to be created dynamically.
>>> My SAO/CAO design is to let server factory object register as IPC
>>> channel(Singelton), each client calls the factory's createInstance
>
> BTW, you don't register an IPC singleton channel. You register
> a channel. On this channel you publish a Sigleton.
>
> What you have to do on the *other* app domains: just
> register an IPC channel with another distinct port name:
>
> string portName = Guid.NewGuid().ToString();
> ChannelServices.RegisterChannel(new IpcChannel(portName));
>
> You don't need t publish the Singleton again!
>
> Rob
>
>>> method to
>>> create another server object. it is this second server object needs to
>>> be
>>> created in a new domain. However I can't predermine this second object's
>>> channel unless I manually fix or limit the number of clients connecting
>>> to
>>> the server, then I can register channel for each domain.
>>
>>
>> Of course you can. What stops you to register the channels?
>> Do it the same way as for the first app domain.
>>
>> If you don't register the channels in the domain, it simply
>> won't work.
>>
>> Rob
>>
>>
>>> Hank
>>>
>>> "Robert Jordan" <robertj@gmx.net> wrote in message
>>> news:dg1sor$1di$00$1@news.t-online.com...
>>>
>>>> Hi Hank,
>>>>
>>>>
>>>>> But my design is to create a the server object and run on a differnt
>>>
>>>
>>> domain
>>>
>>>>> each time a new client request to create
>>>>> a new server object through Factory pattern.
>>>>> Your help is highly appreciated!
>>>>
>>>>
>>>> You need to register a remoting channel in each domain.
>>>> Take care with Tcp and HttpChannels: the port numbers must
>>>> be different per domain.
>>>>
>>>> Rob
>>>
>>>
>>>
>>>