Configuration files location & accessibility

Configuration files location & accessibility

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


marioe2000 posted on Thursday, May 18, 2006

I just got my hands on Lhotka’s VB.NET Business Objects book last weekend and have been living off of it for that last few days (well not true, I did have a little food and some water last night but only because my wife made me do it).

 

I had been struggling for a few weeks trying to construct a very basic class hierarchy to support an OO business model implementation and while researching how to build that I stumbled upon the CSLA on the net. Thank you Rockford Lhotka for sharing your experience and allowing a .NET newbie like me to become productive faster while not sacrificing Object Orientation. I’m currently re-writing my BO’s to use the CSLA and have come to a question I can’t find a clear answer in the book or the forums.

 

I cannot figure out how the configuration files work in a distributed environment where we have different physical tiers for the client and the data server. I fully understand the concept of a .NET object flying across the network from the data portal to the UI and then back again. But my question is where does the .config files go? Must they get deployed to both physical tiers? Is clear to me that the BO can easily find the .config while it’s code runs on the client, but when the BO is running on the server (for a db related process) how does it know where to look for the .config file? Where does it look for it? In the same location as the .dll containing the code for the BO? I’m guessing that’s where is supposed to go but I want to be sure of it and what goes on backstage.

 

Mario Estrella

CIMSA Logistics

Skeeboe replied on Thursday, May 18, 2006

It will use the web.config on the dataportal. Be sure to add the channels section below. I believe its essential for IIS6 but I'm not 100%.

    <system.runtime.remoting>
        <application>
            <service>
                <wellknown mode="SingleCall" objectUri="DataPortal.rem" type="CSLA.Server.DataPortal, CSLA.Server.DataPortal"/>
                <wellknown mode="SingleCall" objectUri="ServicedDataPortal.rem" type="CSLA.Server.ServicedDataPortal.DataPortal, CSLA.Server.ServicedDataPortal"/>
            </service>
                  <channels>
                        <channel ref="http">
                              <serverProviders>
                                    <provider ref="wsdl" />
                                    <!-- TODO: comment the following two lines for .NET 1.0 -->
                                    <formatter ref="soap" typeFilterLevel="Full" />
                                    <formatter ref="binary" typeFilterLevel="Full" />
                    </serverProviders>               
                </channel>
            </channels>
        </application>
    </system.runtime.remoting>

marioe2000 replied on Friday, May 19, 2006

I'm building a winforms application so i'm guessing that the "executable.exe.config" file instead of the web.config file right?

Thanks

ajj3085 replied on Friday, May 19, 2006

Yes, but if you use IIS as a remoting host, you need to setup Web.Config as described above.  If your business logic or data access code requires settings from a configuration file, they'll have to go in Web.config as well as app.exe.config.

guyroch replied on Friday, May 19, 2006

Getting remoting to work the first time involves a few steps.
 
1. Create a web project and copy all CSLA assemblies into the bin directory (or add a reference to all CSLA assemblies).
 
2. Add a web.config file to your web project and add to the following in the web.config file.
 
  <system.runtime.remoting>
    <application>
      <service>
        <wellknown mode="SingleCall"
            objectUri="WebPortal.rem"
            type=" CSLA.Server.DataPortal, CSLA.Server.DataPortal" />
      </service>
      <channels>
        <channel ref="http">
          <serverProviders>
            <provider ref="wsdl" />
            <!-- TODO: comment the following two lines for .NET 1.0 -->
            <formatter ref="soap" typeFilterLevel="Full" />
            <formatter ref="binary" typeFilterLevel="Full" />
          </serverProviders>
        </channel>
      </channels>
    </application>
  </system.runtime.remoting>
 
The objectUri="WebPortal.rem" is a logical name that you are giving to your remoting server.  If you look closely, it points to the "CSLA.Server.DataPortal" assembly - type="CSLA.Server.DataPortal, CSLA.Server.DataPortal".
 
3. Create a virtual directory under IIS and have it pointed to your web project directory created in step 1.  For the purpose of this thread, I will call the virtual directory "MyRemotingTest".
 
4. Then test that remoting is actually working by typing the following in your browser address bar.  If you look closely you will notice the specific location of "MyRemotingTest" and " WebPortal.rem".
 
http://localhost/MyRemotingTest/WebPortal.rem?wsdl
 
If remoting does not works, you will get a page not found error. But if it works, you should get something that starts like this.
 
 <?xml version="1.0" encoding="UTF-8" ?>
- <definitions name="DataPortal" targetNamespace=" http://schemas.microsoft.com/clr/nsassem/CSLA.Server/
 CSLA.Server.DataPortal%2C%20Version%3D1.51.2220.312%2C%20Culture%3Dneu'
 tral%2C%20PublicKeyToken%3D8b12744985d32620"
 
There is no point in doing anything else before you can established that remoting is working. So make sure you make it work before going on.
 
5. Now that you have been able to confirm that remoting does work, modify your app.config file on your client and add the following.  Notice the location of "MyRemotingTest" and "WebPortal.rem", this is very important.
 
 <configuration>
   <appSettings>
     <add key="Authentication" value="CSLA" />
     <add key="PortalServer" value=" http://localhost/MyRemotingTest/WebPortal.rem" />
   </appSettings> 
</configuration>
 
This should now give your client access to the server using remoting.
 
6. For your database connection string, add the following in your web.config file.
 
 <appSettings>
   <add key="Authentication" value="CSLA" />
   <!-- Security Connection String -->
   <add key="DB:Security" value="data source=(local);initial catalog=SecurityDB;user id=sa;password=p1234567;Connect Timeout=120" />
   <!-- Foundation Connection String -->
   <add key="DB:Foundation" value="data source=(local);initial catalog=FoundationDB;user id=sa;password=p1234567;Connect Timeout=120" />
 </appSettings>
Notice that the source=(local) and not localhost. The parenthesis are required.
 
7. I'm using CSLA security in this example, not integrated security.  Also, I'm not using Enterprise Services so I have not included the ServiceDataProtal in this example, just the DataPortal.
 
THIS EXAMPLE IS FOR CSLA 1.x, not 2.0.  But I they are not that different.

Hope this helps
 

marioe2000 replied on Saturday, May 20, 2006

WOW !!! it's amazing to get such rich feedback ... Not only is the CSLA a great framework, but it also has a great community backing it up ....

Thank you All ...

Copyright (c) Marimer LLC