如何将 Web 服务从 Visual Studio 发布到 IIS? [英] How to publish a Web Service from Visual Studio into IIS?

查看:41
本文介绍了如何将 Web 服务从 Visual Studio 发布到 IIS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 C# 编写了一个 WCF Web 服务.我最初是自行托管它,然后决定将它托管在我 PC 上本地运行的 IIS 上.在服务运行时,部署过程中有几个方面我不明白:

I have written a WCF web service in C#. I had originally self-hosted it and then decided to host it on IIS running locally on my PC. While the service is working, there are several aspects of the deployment process that I don't understand:

首先,托管在 IIS 中的此服务的 URL 与我在 web.config 中指定的不对应.我在那里指定了 "http://localhost:8000/MyServices/OrderService" 并且在我自托管.现在我已经部署到 IIS,URL 变成了http://localhost/MyServices/OrderService".为什么没有从我的配置文件中提取 URL?

Firstly, the URL of this service when hosted in IIS does not correspond to what I specified in my web.config. I had specified "http://localhost:8000/MyServices/OrderService" there and this was used when I self-hosted. Now that I've deployed to IIS, the URL has become "http://localhost/MyServices/OrderService". Why is the URL not picked up from my config file?

其次,为了托管 Web 服务,我在 IIS 中创建了一个新网站(除了现有的默认网站"之外).我将物理路径设置为 c:inetpubwwwroot (不知道这是否正确)并将其他参数保留为默认值.然后我将我的/bin 文件夹、我的 .svc 文件和我的 web.config 复制到这个文件夹中.这相当于虚拟目录"吗?

Secondly, to host the Web Service, I created a new web site within IIS (in addition to the existing 'Default Web Site'). I set the physical path to c:inetpubwwwroot (no idea if this is correct) and left the other parameters as default. I then copied my /bin folder, my .svc file and my web.config to this folder. Is this the equivalent of a 'Virtual Directory'?

最后,直到(在 IIS 中)我选择了转换为应用程序",该服务才起作用.为什么必须选择转换为应用程序"?

Finally, the service didn't work until (within IIS) I selected 'Convert to application'. Why is it necessary to select 'Convert to application'?

谁能解释将简单的 Web 服务从 Visual Studio 发布到 IIS 的正确过程,或者指出一些好的文档以便我理解该过程?

Can anyone explain what the correct procedure is to publish a simple web service from Visual Studio into IIS, or point me at some good documentation so I can understand the process?

****编辑为原始文件*****花了更多时间研究这个问题后,我发现了以下内容:

****EDIT TO ORIGINAL***** Having spent more time looking into this, I have found the following:

  • 当我在 IIS 中创建一个网站时,我给它一个物理目录 c:inetpubwwwroot..etc
  • 如果我随后从 Visual Studio 中发布",它所做的只是将所有需要的文件(如/bin 目录、web.config 和 .svc 文件)复制到网站的物理目录中,即 - c:inetpubwwwroot...

您可以手动执行复制以达到相同的效果.

You can perform the copy manually to the same affect.

答案是在 IIS 上托管时完全忽略了 baseAddress.

The answer is that the baseAddress is completely ignored when hosting on IIS.

推荐答案

如果使用 Visual Studio 2010,您可以右键单击该服务的项目,然后选择 properties.然后选择 Web 选项卡.在 Servers 部分下,您可以配置 URL.还有一个创建虚拟目录的按钮.

If using Visual Studio 2010 you can right-click on the project for the service, and select properties. Then select the Web tab. Under the Servers section you can configure the URL. There is also a button to create the virtual directory.

这篇关于如何将 Web 服务从 Visual Studio 发布到 IIS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆