从REST WCF服务中删除.svc,仍然启用“?wsdl”和“/ help”

时间:2011-05-06 01:53:22

标签: wcf web-services iis rest url-rewriting

之前的SO问题/答案都没有引导我找到一个完整的REST / WCF解决方案,该解决方案从服务的各个方面删除了SVC扩展。

具体来说,我指的是servicename/helpservicename/wsdl ......但我知道这是可能的。 {/ 3}}能够从/ help链接中删除WCF扩展名的人员。此外,他无法直接使用扩展名调用.svc。似乎WSDL不存在(虽然我更喜欢保留它)

如何使我的WCF REST应用程序更像该链接?

这是IIS URL Rewrite让我在那里的一部分。这看起来很糟糕,因为如果我没有第一个(两个)重写,那么Web服务随机变得不可思议。

  <system.webServer>
     <modules runAllManagedModulesForAllRequests="true"/>


    <rewrite>
      <rules>
        <rule name="test1.svc" stopProcessing="true" >
          <match url="^test1.svc(.*)$"/>
        </rule>
        <rule name="test1" stopProcessing="true" >
          <match url="^test1(.*)$"/>
          <action type="Rewrite" url="/test1.svc{R:1}" />
        </rule>
      </rules>
    </rewrite>

  </system.webServer>

2 个答案:

答案 0 :(得分:7)

我假设您使用.Net Framework 4,基于您发布的链接。如果是这种情况,则不需要使用.svc文件,因为它现在与ASP.NET routing集成。因此,您可以使用新的ServiceRoute类将服务URL添加到ASP.NET Route table。有关更多信息,请参阅以下article

答案 1 :(得分:-2)

WCF 4还允许您使用无文件激活和Windows激活服务提供别名寻址。 (WAS)

<configuration>
  <system.serviceModel>
    <serviceHostingEnvironment>
      <serviceActivations>
        <add relativeAddress="/GreetingService" service="GreetingService"/>
      </serviceActivations>
    </serviceHostingEnvironment>
  </system.serviceModel>
</configuration>
相关问题