Search code examples
c#wcfurl-rewritingisapi

URL Rewrite Doesn't Work as Expected - Hide svc extension


I'm new to URL Rewrite.

I created a WCF Rest service, and I'm trying to set a rewrite rule that will allow invoking the service when the svc extension is hidden.

I have a method named "Test" on that service, that I invoke successfully with the svc extension present.

What I did:

  1. Created a rule in the web config:

enter image description here

  1. Checked the Rule shows in IIS under ReWrite features.

enter image description here

  1. Validated it works as I expect by clicking the "test pattern" button and entering the URL details:

enter image description here

  1. Did IISReset (Several times).

  2. I'm getting a 404 when trying this URL:

http://localhost/WcfTestApp/Service1/Test

Additional Stuff:

I also enabled "Failed Request Tracing Rules" But I see no logs created in the folder.

Any Ideas why it isn't working as I expect?

Thanks in advance for any help.


Solution

  • What I did to resolve it:

    1. I fixed the failed request tracing log files not appearing, turns out you need to configure in the IIS settings the status codes for which the trace should occur, as it's not smart enough to select all by default.

    2. Then via the trace file (which I opened in IE), I noticed my rewrite rule needed a slight modification, as I was able to see what URL I got, and what it was rewritten to (which did not work).

    Eventually, that's what I used.

    <rule name="RemoveSvcExtension" stopProcessing="true">
      <match url="^(.*)Service1/(.*)$" />
      <action type="Rewrite" url="{R:1}Service1.svc/{R:2}" logRewrittenUrl="true" />
    </rule>