在 IIS 主机中自定义 WCF 服务端点地址 [英] Customize WCF Service endpoint address in IIS Host

查看:41
本文介绍了在 IIS 主机中自定义 WCF 服务端点地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to change the endpoint address on a WCF service when using IIS Hosting, I current just point to the svc file but I would like to use RESTful commands?

推荐答案

.NET 4 中的 WCF 将支持所谓的无文件激活,这将允许您定义任意 URL,并将其映射到 WCF 服务.

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.

查看开发人员对 WCF 4 的介绍,了解一些信息,或阅读此博客文章 专门针对无文件激活.

Check out the Developer's Introduction to WCF 4 for some info, or read this blog post specifically on file-less activation.

基本上,在 WCF 4 中,您可以向 web.config 添加一个条目:

Basically, in WCF 4, you can add an entry to your web.config:

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

因此,将浏览器指向 http://YourServer/Services/MyService 将激活该特定服务.

and thus, pointing your browser to http://YourServer/Services/MyService would then activate that particular service.

Ron Jacobs 也有一个 REST 服务的有趣方法,他注册了一个路由来避开 *.svc 文件 - 他为 WCF 数据服务解释了这一点,但这是我的感觉,这应该适用于所有 WCF REST服务,真的.但它也是 .NET 4 独有的功能.

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. But it's a .NET 4 only feature, also.

这篇关于在 IIS 主机中自定义 WCF 服务端点地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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