tags:

views:

807

answers:

2

I have a WCF service that calls, through a BL, a Data Layer and ultimately SQL Server back-end. My service exposes various methods/operations to get data out of the database. I have also built a host for it for testing, and a Windows Service Host, which is how I plan to deploy it.

Yesterday when I did a test-deploy, the service started fine but I didn't get a chance to see if the data was pulling properly. Here's the thing: My deployment Test environment (MS Server 2003) is totally different than my own (laptop) local test enviro. I deployed by copying out the bin\debug contents of the Windows Service project onto the server and referencing the .exe there when I used InstallUtil.exe. But the data connection for the DL should take a different connection string, obviously, as it should be connecting to the database on the server, not my laptop. Yet the only app.config I see in the directory I deployed to is the one for the service host. The other projects, like the DL and BL, are also there as DLL's, but no app.config's for either. So how can I replace the app.config for the DL with the correct one for that enviro? I'm sure this is a simple problem that I'm just not cluing in on.

A related question: If we decide later that we want to use an HTTP host instead of - or in addition to - TCP, can I run a second host driving off that same service? Do I just need to deploy the host with IIS and add a service node to the app.configs?

A: 

App.config for the hosting environment, in this case the managed Windows service, contains the configuration for all your modules. Similarly, Web.config contains all configurations if you host it on IIS.

eed3si9n
So anything for, say, the data layer's app.config, like the connection string, should be re-housed in the service's config instead? IOW, any config stuff from any of the modules needs to be in the host's config at deployment.
Mike at KBS
Right. You merge everything on one config file.
eed3si9n
+1  A: 

When you deploy a project, the only app.config/web.config you will get is the one that is in your executable project (website/console app/windows service/windows forms app/etc. project). Any app.configs for DLL projects will not be copied into the bin directory.

You'll need to copy the config sections out of your DLL projects and put them in your service project app.config.

For your second question, you can host different endpoints for the same service in the same ServiceHost. You can host an HTTP endpoint in a windows service/console app. If you host HTTP outside of IIS, you may need to give permissions to your user to allow it to open an HTTP port. (see http://msdn.microsoft.com/en-us/library/ms733768.aspx ). For HTTP your life might be easier hosting in IIS, but it does work in a plain ServiceHost.

<system.serviceModel>
    <services>
        <service name="MyServiceTypes.MyService">
            <endpoint address="http://localhost:44444/MyService"
                      binding="basicHttpBinding"
                      contract="MyServiceTypes.IMyService" />

            <endpoint address="net.tcp://localhost:55555/MyService"
                      binding="netTcpBinding"
                      contract="MyServiceTypes.IMyService" />
        </service>
    </services>
</system.serviceModel>
Andy White