在WCF中使用REST时,如何去掉URL中的.svc后缀

以Windows 7里面的IIS7.5为例。

假设我们的service method样子为

 

< WebGet(UriTemplate: = " {parameter} " ) >  _
        
< OperationContract() >  _
        
Function  ServiceMethod( ByVal  parameter  As   String As   Boolean

 

我们希望将一个这样的url

http://localhost/SomeService/ServiceMethod.svc/Parameter
使用

 

 

http://localhost/SomeService/ServiceProvider/Parameter

来访问

 

首先从这里安装一个URLRewrite。

 安装后打开IIS,从Features View里面可以看到URL Rewrite设置图标。

 

 双击进入设置,选择Add Rule(s)...然后选择Blank Rule

进行如下设置

 

Fill out the form with the following data (we will describe the patterns in detail in a moment):
  1. Name:                       RemoveSvcExtension (or any name you want)
  2. Requested URL:         Matches the pattern
  3. Using:                       Regular Expressions
  4. Pattern:                    ^([0-9a-zA-Z\-]+)/([0-9a-zA-Z\-\.\/\(\)]+)
  5. Ignore Case:             Checked
  6. Action Type:              Rewrite
  7. Rewrite URL:             {R:1}.svc/{R:2}
  8. Append QueryString   Checked
 

 

 稍微解释一下Regex Pattern的含义。

 

  • The "^" indicates the beginning of the line or string
  • The parenthesis "()" allow you to define a numbered capture group, meaning that you can reference everything inside the parens later by index.  In our example, we have 2 numbered capture groups 1 and 2.  You refer back to these later with the syntax: {R:1} and {R:2}
  • The pattern [0-9a-zA-Z\-]+ indicates any character in 0-9, lowercase a-z, uppercase A-Z or "-", one or more repetitions.
  • The / is a straight match to a slash "/".  In other words, the first named capture group will capture 0-9,a-z, A-Z and "-" prior to the first "/" and you will be able to reference them with {R:1}
  • Then we have another named capture group
  • The pattern [0-9a-zA-Z\-\.\/\(\)] matches any character in 0-9, lowercase a-z, uppercase A-Z or "-", ".", "/", "(", ")", one or more repetitions.
 

 

 

转载于:https://www.cnblogs.com/sayo/archive/2011/07/08/2101307.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值