Can you nest WCF services in the same IIS app?

While working on the team's Tier Services testbed, that is a collection of WCF services for testing purposes, when I ran into the following issue:

[Directory Structure]

Now foobar.svc would work fine, but foobar2.svc would give me the following error:
The type 'X', provided as the Service attribute value in the ServiceHost directive could not be found.

What that translates to is that WCF was trying to load up the type X to host the service but couldn't find it.  The SVC file says that the CodeBehind="~/App_Code/foobar2.vb".  It should work, right?

Well no, it shouldn't.  I expected it would, but let me explain why not.  When you create an IIS application the only /bin or /App_Code folder is in the root directory of the IIS app.  So rather than looking for the type X in foobar2.vb in \SubFolder\App_Code\, it was checking \App_Code\.

So having multiple services in the same IIS application node is OK, just remember that you have to put all the code in the root /bin or /App_Code directory.


Comments (5)

  1. annesh singh says:

    I have almost replicated this scenario,lets say in the root web.config you have a key

    <add key=’whereami’ value=’root’/>

    and in the SubFolder you want to overwrite this setting <add key=’whereami’ value=’subfiolder’/>

    then in ur service when u use configurationmanager.appsettings[‘whereami’] returns the ‘root’ even though you executing from the subfolder. Why?

  2. randyk says:

    This error must be a bogus Microsoft error. I still get this error after verifying and complying with about 6 different suggestions to fix it.

  3. randyk says:

    I figured this out!

    There was a change in the "Service" syntax of the "@ServiceHost" directive in the svc class. You now must include the service name and the namespace the service is in (delimited by a comma).


    Service="MyCompany.UpdateMachines.UpdateBigStuff.Service, MyCompany.UpdateMachines"

  4. Aaron says:

    Thank you. This helped me solve the same problem I was having, while trying Microsoft’s "Microsoft.ServiceModel.Samples.CalculatorService"on a Windows 2003 server. I moved the files out of  the ServiceModelSamples directory, and into the wwwroot directory. Then the service worked.


  5. Aaron says:

    Moving the bin folder did work for me, as I stated above. But there was another way to make this work: I got rid of the directory ServiceModelSamples and created a new Virtual Directory with that name.

    It turns out that the servicemodelsamples created by the MSDN setup tool was not a Virtual Directory at all.

Skip to main content