简体   繁体   English

在 IIS 主机中自定义 WCF 服务端点地址

[英]Customize WCF Service endpoint address in IIS Host

使用 IIS 托管时是否可以更改 WCF 服务上的终结点地址,我当前只是指向 svc 文件,但我想使用 RESTful 命令?

Discussed in Overview of REST in WCF . 在 WCF 中的 REST 概述中讨论。 They point to the WCF REST Starter Kit .它们指向WCF REST Starter Kit

The WCF REST Starter Kit is a set of .NET Framework classes and Visual Studio features and templates that enable users to create and access REST-style Windows Communication Foundation (WCF) services. WCF REST Starter Kit 是一组 .NET Framework 类和 Visual Studio 功能和模板,使用户能够创建和访问 REST 样式的 Windows Communication Foundation (WCF) 服务。 These services are based on the WCF web programming model available in .NET 3.5 SP1.这些服务基于 .NET 3.5 SP1 中可用的 WCF Web 编程模型。 The starter kit also contains the full source code for all features, detailed code samples, and unit tests.入门工具包还包含所有功能的完整源代码、详细的代码示例和单元测试。

WCF in .NET 4 will support so-called file-less activation, which will allow you to define any arbitrary URL, and map that to a WCF service. .NET 4 中的 WCF 将支持所谓的无文件激活,这将允许您定义任意 URL,并将其映射到 WCF 服务。

Check out the Developer's Introduction to WCF 4 for some info, or read this blog post specifically on file-less activation.查看开发人员的 WCF 4 简介以获取一些信息,或阅读这篇专门关于无文件激活的博客文章

Basically, in WCF 4, you can add an entry to your web.config:基本上,在 WCF 4 中,您可以在 web.config 中添加一个条目:

<serviceHostingEnvironment  >
   <serviceActivations>
       <add factory="System.ServiceModel.Activation.ServiceHostFactory" 
            relativeAddress="/Services/MyService" 
            service="MyServiceClass"/>
   </serviceActivations>
 </serviceHostingEnvironment>

and thus, pointing your browser to http://YourServer/Services/MyService would then activate that particular service.因此,将浏览器指向http://YourServer/Services/MyService将激活该特定服务。

Ron Jacobs also has an interesting approach for REST services , where he registers a route to avoid the *.svc file - he explains this for the WCF Data Services, but it's my feeling, this should work for all WCF REST services, really. Ron Jacobs 也有一个有趣的 REST 服务方法,他注册了一个路由来避开 *.svc 文件 - 他为 WCF 数据服务解释了这一点,但我的感觉是,这应该适用于所有 WCF REST 服务,真的。 But it's a .NET 4 only feature, also.但它也是 .NET 4 的唯一功能。

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

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