简体   繁体   English

如何将WCF部署到IIS并使它保持活动状态

[英]How To Deploy WCF To IIS And Have It Stay Alive

I've created a basic WCF service library project and deployed it to my local IIS installation (7.5). 我已经创建了一个基本的WCF服务库项目,并将其部署到了本地IIS安装(7.5)。 Whenever I try to navigate to it via localhost/TestWcfServiceLibrary/ I just get a directory view. 每当我尝试通过localhost / TestWcfServiceLibrary /导航到它时,我只会得到目录视图。

However, if I start the service in debug mode from visual studio, I get the system tray popup telling me that it's been hosted, and then when I go back to localhost/TestWcfServiceLibrary/, I'm able to see the wsdl. 但是,如果我从Visual Studio以调试模式启动服务,则会弹出系统托盘弹出窗口,告诉我它已经托管,然后回到localhost / TestWcfServiceLibrary /时,便可以看到wsdl。 As soon as I stop debug mode and refresh the browser, I'm back to the directory view. 一旦我停止调试模式并刷新浏览器,便回到目录视图。

The base address in the config file is localhost/TestWcfServiceLibrary/ so I don't understand why I'm seeing this behavior. 配置文件中的基址是localhost / TestWcfServiceLibrary /,因此我不明白为什么会出现此行为。

Interestingly, if I navigate to localhost/TestWcfServiceLibrary/service.service1.svc (A file that doesn't exist) I get the wsdl even when debug mode is off. 有趣的是,如果我导航到localhost / TestWcfServiceLibrary / service.service1.svc(一个不存在的文件),即使关闭调试模式,我也会得到wsdl。

So I have 2 questions. 所以我有两个问题。

1) Why does debug mode in visual studio have any affect at all on whether or not I can access the wsdl from the path localhost/TestWcfServiceLibrary ? 1)为什么Visual Studio中的调试模式对我是否可以从本地主机/ TestWcfServiceLibrary路径访问wsdl完全没有影响? (I suspect it's because the wcf service is not technically hosted at "localhost", it's hosted at , so the address doesn't really exist until debug mode is turned on, so I'm actually connected to the temporarily hosted version that visual studio provides and NOT the real IIS hosted webservice?) (我怀疑这是因为wcf服务不是从技术上托管在“ localhost”上,而是托管在上,因此该地址在打开调试模式之前并不存在,因此实际上已连接到Visual Studio的临时托管版本提供但不提供真正的IIS托管的Web服务?)

2) When deploying a WCF service library directly to IIS, is it always correct to point to the .svc file with a the namespace and class name of your service contract, even though that file doesn't really exist (I'm guessing that's the magic that IIS performs for you)? 2)当直接将WCF服务库部署到IIS时,指向.svc文件是否带有服务合同的名称空间和类名总是正确的,即使该文件实际上并不存在(我猜这是IIS为您执行的魔术)?

1) You can see where your webservice is hosted in the Web tab of the properties of your WCF project. 1)您可以在WCF项目属性的“ Web”选项卡中看到Web服务的托管位置。 Default behavior in VS.NET is to host your project in IISExpress, a mini IIS that comes with Visual Studio.NET and that is automatically started when you run a service. VS.NET中的默认行为是在IISExpress中托管您的项目,IISExpress是Visual Studio.NET附带的一个微型IIS,在您运行服务时会自动启动。 So, if you haven't changed the default then yes, your service is technically hosted at "localhost", but not on port 80 in IIS but on another port in IISExpress (The exact port varies)... I guess it's IISExpress that decides to give you the wsdl when you browse to the service address. 因此,如果您没有更改默认值,那么可以,您的服务在技术上是托管在“ localhost”上,而不是在IIS的端口80上,而是在IISExpress的另一个端口上(确切的端口有所不同)...我想这是IISExpress当您浏览到服务地址时,决定给您wsdl。 That is not default behaviour of IIS. 这不是IIS的默认行为。 That will show the folder contents if directory browsing is enabled in the web.config, and otherwise gives you a 404 (not found) error. 如果在web.config中启用了目录浏览,则将显示文件夹内容,否则将显示404(未找到)错误。

2) There are 2 ways to activate a WCF service in IIS. 2)有两种方法可以在IIS中激活WCF服务。 Either you provide a real .svc file that lists what service implementation IIS should start. 您可以提供一个真实的.svc文件,该文件列出了IIS应该启动的服务实现。 Either you indicate that in the node in your web.config file. 您可以在web.config文件的节点中进行指示。 It is the .svc part of the URL that triggers IIS to start the service. URL的.svc部分触发IIS启动服务。

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

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