Change CslaDataPortalUrl Setting at runtime?

Change CslaDataPortalUrl Setting at runtime?

Old forum URL: forums.lhotka.net/forums/t/1329.aspx


brembot posted on Monday, September 25, 2006

Hello All,

Does anyone know this? I want to change the CslaDataPortalUrl at runtime. Why i'm doing this because we have many servers running. We have to setup .net remoting in our application in each server. Each servers has its own CslaDataPortalUrl Setting. How am i going to achieve this goal without hacking the ApplicationContext of DataPortal. Here's the sample setup below.

Click Once deployment (all users can access this and install the application)
http://SharedLocation:6040/publish.htm

.NET Remoting setup in all servers (New Zealand, Japan, Philippines, Usa, etc...)
MyProject.exe
MyProject.dll
Csla.dll
MyProject.exe.config
Web.config

Users for New Zealand will connect thru this Url
<add key="CslaDataPortalUrl" value="http://NewZealand:6040/RemotingPortal.rem"/>

Users for Japan will connect thru this Url
<add key="CslaDataPortalUrl" value="http://Japan:6040/RemotingPortal.rem"/>

Users for Philippines will connect thru this Url
<add key="CslaDataPortalUrl" value="http://Philippines:6040/RemotingPortal.rem"/>

Users for Usa will connect thru this Url
<add key="CslaDataPortalUrl" value="http://Usa:6040/RemotingPortal.rem"/>


Thanks,
Marlon

RockfordLhotka replied on Monday, September 25, 2006

This has been discussed before on the forum. The data portal channels provided in the book do not support this concept. However, using the information in chapters 4 and 12, you can create your own data portal channel (the WcfChannel on my web site is a useful guide too).

If I recall the previous threads, it seems to me that one or two people did, in fact, go down that road with success. If you adapt the RemotingProxy to your needs, you can typically have it just call the existing RemotingHost class, and so it isn't really very hard to do. Just copy RemotingProxy to your own assembly, alter it to find the URL using your new scheme and configure the client to use your new class from your assembly.

RichardETVS replied on Monday, August 13, 2007

Hi Rockford and Marlon

 

Marlon, if you're still around, would you be kind enough to tell us how did you resolve your problem? Thank you very much.

Rockford, do you mean that in the CSLA\DataPortal\Client\RemotingProxy.cs file, we have to change those lines :

      HttpChannel channel = new HttpChannel(properties, formatter, null);
      ChannelServices.RegisterChannel(channel, EncryptChannel);

to choose the server? Or did I misundertand?

 

And that can work while the client is running? We need to change the server while the client is running. The idea is that the client can work without interruption if the server goeds down.

Thank you a lot for your help

 

RichardETVS replied on Monday, September 03, 2007

Anyone :) ?

 

Thanks

RockfordLhotka replied on Monday, September 03, 2007

RichardETVS:

Rockford, do you mean that in the CSLA\DataPortal\Client\RemotingProxy.cs file, we have to change those lines :

      HttpChannel channel = new HttpChannel(properties, formatter, null);
      ChannelServices.RegisterChannel(channel, EncryptChannel);

to choose the server? Or did I misundertand?

I mean that you would copy RemotingProxy.cs into your project and then alter it as needed to allow selection of different endpoint URLs. You don't need to change CSLA itself to do this.

See Chapter 4 for discussion on how RemotingProxy works. But some pointers are that it gets the URL from the config file - you need to change that somehow. Also, it caches the server proxy and you can't do that if you want to dynamically switch (or you must clear the cache if you change the URL).

The lines you point out probably won't change, no. But many other lines will need to change, and you'll need to figure out how to change the URL at runtime, etc.

Remember that none of your code ever has a reference to RemotingProxy. The data portal creates it behind the scenes. So the only real way to communicate with it is through static methods.

xal replied on Monday, September 03, 2007

Well, if all you need to do is change the setting when the application loads instead of changing it dynamically, you can directly change the url in your app settings like this:

System.Configuration.ConfigurationManager.AppSettings("CslaDataPortalUrl") = "http://..."

Doing that before calling the dataportal for the first time will do.

If you need something more complex that can dynamically change dataportals as you go, you can take a look at this. It shows you how to use different proxys and you can use the same technique i showed you before to load standard remoting proxies and keep them cached.

I hope that helps.

Andrés

Copyright (c) Marimer LLC