简体   繁体   中英

Remove .svc from REST WCF service with “?wsdl” and “/help” still enabled

None of the prior SO questions/answers lead me to a complete REST / WCF solution that removes the SVC extension from all aspects of the service.

Specifically I'm referring to servicename/help and servicename/wsdl ... but I know it's possible. Here is a working example of someone who is able to remove the WCF extension from the /help link. In addition he made it impossible to call the .svc directly with the extension. It appears that the WSDL is non existent (though I'd prefer to keep this)

How do I make my WCF REST application act more like that link?

Here is the IIS URL Rewrite that gets me part way there. It seems kind of hokey because if I don't have the first (of two) rewrites then the web service randomly gets borked.

  <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>

I'm assuming that you are using .Net Framework 4, based on the link you posted. If this is the case, you don't need to use .svc files, because it now integrates with ASP.NET routing . Therefore, you can use the new ServiceRoute class to add your service URLs to the ASP.NET Route table . For more information see the following article .

WCF 4 also allows you to provide alias addressing using fileless activation and Windows Activation Services. (WAS)

<configuration>
  <system.serviceModel>
    <serviceHostingEnvironment>
      <serviceActivations>
        <add relativeAddress="/GreetingService" service="GreetingService"/>
      </serviceActivations>
    </serviceHostingEnvironment>
  </system.serviceModel>
</configuration>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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