简体   繁体   中英

Multiple Web/WCF Projects in One IIS Application

An Visual Studio project, for ASP.NET or WCF, typically is assigned one-to-one with an IIS application. But what if, for example, I want two WCF projects to be hosted in the same appdomain within IIS? This implies that I would have two Visual Studio WCF projects assigned to a single IIS application.

I started to try this out, and ran into the first error message . I've seen comments suggesting how "not to do this." But in my case, I actually want to do this. I don't mind if this means having three web configs for the IIS application (one at the root of the IIS app, the other two in "project" folders it contains) or if it means having only one web config for the IIS application.

So for my two Visual Studio WCF projects, I've shuffled around web.config contents in a variety of ways:

  • One IIS application, pointing at the physical directory where my Visual Studio solution file is found. The two WCF projects are in two respective subfolders
  • One IIS application, pointing at some arbitrary physical location, containing two virtual directories pointing to the two WCF project physical directories, respectively. I have three web config files here: one for the IIS app root, the other two in the virtual directories.

A variation of the second option above nearly worked. The final error message I got was:

The type 'Sample.ServiceGroupAlpha.ServiceAlpha', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
Description : An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details : System.InvalidOperationException: The type 'Sample.ServiceGroupAlpha.ServiceAlpha', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.

This prompted me to look at the ServiceHost directive, and (coyly) modify it:

<%@ ServiceHost Language="C#" Debug="true" Service="Sample.ServiceGroupAlpha.ServiceAlpha" CodeBehind="AlphaServices/ServiceAlpha.svc.cs" %>

...notice the CodeBehind attribute has a relative path I added (the name of the virtual directory). Well, this didn't work, but I can't help but think I'm close to making this work. I'd like to know if anyone has a fix, or can relay the "correct" way to accomplish this whole thing.

Ultimately the answer may be that there is no such thing as having two separate web/WCF projects within the same IIS application; I would be surprised if that was the case. Another answer may be "combine the two WCF projects into a single Visual Studio project/binary." Please assume I don't want that answer either.

Focusing on WCF, at this time I think the closest answer is to use and have multiple VS "WCF Service Library" projects all participate in a single VS "WCF Service Application."

If the approach I outlined in my question were to work "as is," I suspect the aforementioned link may again have the answer. Instead of this...

<%@ ServiceHost Language="C#" Debug="true" Service="WcfWebService.Service1" 
    CodeBehind="Service1.svc.cs" %> 

I would use something like this...

<%@ ServiceHost Language="C#" Debug="true" Service="WcfServiceLibrary.Service1" %>
<%@ Assembly Name="WcfServiceLibrary" %>

I no longer have the time or need to try this, but it seems the above adjustment would handle the last issue I brought up in my question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM