Search code examples
c#.netwcfiiswcf-binding

WCF Service on IIS. How to get rid of the "Service.svc" component in the URL path?


I have a WCF Service hosted on IIS. For business reason I cannot post the public URL of this instance, but I'm sure you will get what I mean:

The problem is that in order to reach my endpoint it seems I have include the Service.svc as part of the path segment, i.e., I have to use URLs like this:

http://<domain>/<app-name>/Service.svc/<relative-path>

How can I avoid this? I mean, I'd like to access my service simply with:

http://<domain>/<app-name>/<relative-path>

I was perfectly able to do this when I was self-hosting the service during development.


Lastly, but this is not-so-transcendental, browsing to the http://<domain>/<AppName>/Service.svc URL displays the standard service information page:

Is there a way I could also prevent this from being accessible?

enter image description here


Solution

  • First part: to not have the "service.svc" part of the URL, you can use the ASP.NET Routing feature, and the ServiceRoute class - the prefix for your route would be the empty string. The post at http://blogs.msdn.com/b/endpoint/archive/2010/01/25/using-routes-to-compose-wcf-webhttp-services.aspx shows how this can be done.

    Second part: to prevent that "help" page from being shown, you can disable it via config (or via code using a custom service host factory). Here's how it can be done via config:

    <serviceBehaviors>
        <behavior>
            <serviceDebug httpHelpPageEnabled="false" httpsHelpPageEnabled="false"/>
        </behavior>
    </serviceBehaviors>
    

    The behavior does not have the "name" attribute, which means that it will be used as the default behavior for services.