How to remove the “.svc” extension in RESTful WCF

2019-01-06 08:52发布

In my knowledge, the RESTful WCF still has ".svc" in its URL.

For example, if the service interface is like

[OperationContract]
[WebGet(UriTemplate = "/Value/{value}")]
string GetDataStr(string value);

The access URI is like "http://machinename/Service.svc/Value/2". In my understanding, part of REST advantage is that it can hide the implementation details. A RESTful URI like "http://machinename/Service/value/2" can be implemented by any RESTful framework, but a "http://machinename/Service.svc/value/2" exposes its implementation is WCF.

How can I remove this ".svc" host in the access URI?

标签: wcf rest
7条回答
爷的心禁止访问
2楼-- · 2019-01-06 09:38

In IIS6 or 7, you can use IIRF, a free rewriting filter. Here's the rule I used:

# Iirf.ini
#

RewriteEngine ON
RewriteLog  c:\inetpub\iirfLogs\iirf-v2.0.services
RewriteLogLevel 3
StatusInquiry  ON  RemoteOk
CondSubstringBackrefFlag *
MaxMatchCount 10

# remove the .svc tag from external URLs
RewriteRule  ^/services/([^/]+)(?<!\.svc)/(.*)$    /services/$1.svc/$2  [L]
查看更多
登录 后发表回答