简体   繁体   English

一个IIS应用程序中的多个Web / WCF项目

[英]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. 通常,针对ASP.NET或WCF的Visual Studio项目与IIS应用程序是一对一分配的。 But what if, for example, I want two WCF projects to be hosted in the same appdomain within IIS? 但是,例如,如果我希望将两个WCF项目托管在IIS的同一appdomain中,该怎么办? This implies that I would have two Visual Studio WCF projects assigned to a single IIS application. 这意味着我将把两个Visual Studio WCF项目分配给一个IIS应用程序。

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. 我不介意这是否意味着为IIS应用程序提供三个Web配置(一个位于IIS应用程序的根目录,另外两个位于“项目”文件夹中),或者是否意味着仅具有一个IIS应用程序的Web配置。

So for my two Visual Studio WCF projects, I've shuffled around web.config contents in a variety of ways: 因此,对于我的两个Visual Studio WCF项目,我以各种方式改编了web.config内容:

  • One IIS application, pointing at the physical directory where my Visual Studio solution file is found. 一个IIS应用程序,指向找到我的Visual Studio解决方案文件的物理目录。 The two WCF projects are in two respective subfolders 这两个WCF项目位于两个子文件夹中
  • One IIS application, pointing at some arbitrary physical location, containing two virtual directories pointing to the two WCF project physical directories, respectively. 一个IIS应用程序,指向某个任意物理位置,其中包含两个虚拟目录,分别指向两个WCF项目物理目录。 I have three web config files here: one for the IIS app root, the other two in the virtual directories. 我在这里有三个Web配置文件:一个用于IIS应用程序的根目录,另外两个用于虚拟目录。

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. 找不到类型'Sample.ServiceGroupAlpha.ServiceAlpha',该类型作为ServiceHost指令中的Service属性值提供,或在配置元素system.serviceModel / serviceHostingEnvironment / serviceActivations中提供。
Description : An unhandled exception occurred during the execution of the current web request. 描述 :在执行当前Web请求期间发生未处理的异常。 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. 异常详细信息 :System.InvalidOperationException:类型'Sample.ServiceGroupAlpha.ServiceAlpha',作为ServiceHost指令中的Service属性值提供,或在配置元素system.serviceModel / serviceHostingEnvironment / serviceActivations中提供。

This prompted me to look at the ServiceHost directive, and (coyly) modify it: 这促使我查看ServiceHost指令,并(轻易地)对其进行修改:

<%@ 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). ...注意, CodeBehind属性具有我添加的相对路径(虚拟目录的名称)。 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; 最终的答案可能是,在同一个IIS应用程序中不存在两个单独的Web / WCF项目。 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." 另一个答案可能是“将两个WCF项目合并为一个Visual Studio项目/二进制文件”。 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." 现在,重点关注WCF,我认为最接近的答案是使用并让多个VS “ WCF服务库”项目全部参与单个VS“ WCF服务应用程序”。

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. 我不再有时间或需要尝试此操作,但是上述调整似乎可以解决我在问题中提出的最后一个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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