Share via


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]
\web.config
\foobar.svc
\App_Code\foobar.vb
\SubFolder\web.config
\SubFolder\foobar2.svc
\SubFolder\App_Code\foobar2.vb

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

  • Anonymous
    September 04, 2008
    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?

  • Anonymous
    November 19, 2008
    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.

  • Anonymous
    November 19, 2008
    I figured this out! There was a change in the "Service" syntax of the "@ServiceHost&quot; directive in the svc class. You now must include the service name and the namespace the service is in (delimited by a comma). Example: Service="MyCompany.UpdateMachines.UpdateBigStuff.Service, MyCompany.UpdateMachines"

  • Anonymous
    June 10, 2009
    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. Thanks

  • Anonymous
    June 10, 2009
    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.