IIS 中的 WCF 托管已简化





3.00/5 (2投票s)
IIS 中的 WCF 托管已简化
这是 WCF 托管教程系列的第 3 部分,我们将实现如何在 IIS(版本 5 或 6)中托管 WCF 服务? 在本系列中,我们已经实现了以下内容:
Microsoft 在 .NET Framework v 3.0 中引入了 WCF(Windows Communication Foundation),具有许多令人兴奋的功能,但其中最令人兴奋的功能是它与 ASMX 服务 或 ASP.NET Web Services 有何不同? 或者与 ASMX 服务相比,它提供了哪些额外的功能?
主要区别在于,ASMX 或 ASP.NET Web Service 旨在仅通过 HTTP 使用 SOAP 发送和接收消息。 而 WCF 可以使用任何格式(默认情况下为 SOAP)通过任何传输协议(HTTP、TCP/IP、MSMQ、命名管道等)交换消息。 另一篇 WCF 教程详细讨论了 WCF 与 ASMX 的区别,请点击此处查看。
因此,如果我们要在 IIS(版本 5 或 6)中托管 WCF 服务,则 HTTP 选项是唯一的可用传输协议。 在较新版本的 IIS(Internet Information Services)中,我们可以使用任何其他协议(TCP/IP、MSMQ、命名管道等)作为传输协议。
WCF RESTful 服务的实用指南
正如我们已经知道的,为了托管 WCF 服务,我们需要一个托管进程。 在 IIS(Internet Information Services)的情况下,它提供主机进程,并在第一个请求到达服务器时启动该进程。
现在,让我们首先创建一个 WCF 服务,然后将其托管在 IIS 中。
创建一个 StudentService 类库
我们在实现 WCF 自托管教程 时,已经创建了一个 StudentService
类库项目。 为了保持一致性,我们将使用相同的服务,因此请参阅该 WCF 教程 的步骤 1 以创建 WCF 服务。
在 IIS 中托管 WCF
因此,为了在 IIS 中托管我们的 WCF 服务,请按照简单的分步方法操作。
- 在解决方案中添加一个网站。 选择“ASP.NET 空白网站”模板。 对于 Web 位置,选择“HTTP”而不是“文件系统”,提供路径并按“确定”按钮。
- 将
StudentService
项目的引用添加到我们的网站,即StudentIISHost
。 - 将
System.ServiceModel
的引用添加到网站。 - 将一个新的 .svc 文件添加到我们的网站项目,如下所示:
在上面的代码中,我们在
ServiceHost
中将Service
指向StudentService
。 - web.config 中
System.ServiceModel
的更新配置如下:<system.serviceModel> <behaviors> <serviceBehaviors> <behavior name=”StudentServiceBehavior”> <serviceMetadata httpGetEnabled=”true”/> <serviceDebug includeExceptionDetailInFaults=”false”/> </behavior> </serviceBehaviors> </behaviors> <services> <service behaviorConfiguration=”StudentServiceBehavior” name=”StudentService.StudentService”> <endpoint address=”https:///StudentIISHost/MyStudentHost.svc” binding=”wsHttpBinding” contract=”StudentService.IStudentService”> <identity> <dns value=”localhost”/> </identity> </endpoint> <endpoint address=”mex” binding=”mexHttpBinding” contract=”IMetadataExchange”/> </service> </services> </system.serviceModel>
- 使用以下路径访问托管的 WCF 服务,即
StudentService
:https:///StudentIISHost/MyStudentHost.svc
希望本 WCF 教程能帮助您理解在 IIS(Internet Information Service)中托管 WCF 服务的实现。
其他相关文章
- 创建您的第一个 WCF RESTful 服务的 5 个简单步骤
- 前 10 名 WCF 面试题
- WCF 与 ASMX 服务
- MVC3 与 MVC4 与 MVC5
- 使用 jQuery 消费 WCF RESTful 服务
- 使用 jQuery 向 WCF RESTful 服务发布 JSON 数据
- 前 10 名 ASP.NET 面试问题和答案
- ASP.NET WebForms 和 ASP.NET MVC 之间的区别
- 前 10 名 HTML5 面试问题和答案
文章 IIS 中简化的 WCF 托管 首先发表在 WCF 教程 上。