1

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

Fernando Espinosa
  • 4,625
  • 1
  • 30
  • 37
  • 1
    looks like you are looking for extensionless urls. see this link http://stackoverflow.com/questions/2921802/serviceroute-webservicehostfactory-kills-wsdl-generation-how-to-create-extens – EdmundYeung99 Jul 11 '12 at 20:10
  • Wow... looks so simple! The info was tremendous, thanks. I ended up using a Global.asax file and adding a `ServiceRoute` with empty routePrefix as suggested below. – Fernando Espinosa Jul 11 '12 at 23:31

4 Answers4

5

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.

carlosfigueira
  • 85,035
  • 14
  • 131
  • 171
3

Step-by-step instructions for .net newbs like myself:

  1. Open your Web.config file and ensure that the aspNetCompatibilityEnabled is set to true:

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    
  2. Right click on the project, click Add->New Item. Find "Global Application Class". This will auto-generate a Global.asax file.

  3. Open Global.asax file and ensure the Application_Start method looks as follows:

    protected void Application_Start(object sender, EventArgs e)
    {
        RouteTable.Routes.Add(new ServiceRoute("", new ServiceHostFactory(), typeof(MyServiceImplementation)));
    }
    

(Change MyServiceImplementation with whatever your class inside Service1.svc is called)

  1. Ensure you've added the following references:

    using System.ServiceModel.Activation;
    using System.Web.Routing;
    

If these aren't found and you are using something earlier than .net 4.5, make sure you are using the full install instead of the client install. Also make sure you've added these package references (right click-project, click Add->Reference, find the package name and ensure it's checked).

  1. Restart IIS. The Service1.svc (or whatever yours was called) file should now be hidden.
Martin Konecny
  • 57,827
  • 19
  • 139
  • 159
1

you can reach this by simply not exposing your service metadata - just comment endpoint

 <endpoint address="mex" binding="mexHttpBinding" name="IMetadataExchange_mexHttpBinding" contract="IMetadataExchange" />

According url - I simply agree with @Edmund Y - he provided useful link

Andriy Zakharko
  • 1,623
  • 2
  • 16
  • 37
0

I'm only curious to know if what I did to implement @carlosfigueira's advice was the best cleanest thing:

I ended up using a Global.asax file and adding a ServiceRoute with empty routePrefix in the Application_Start handler. I'm not too sure why I'm using WebServiceHostFactory vs ServiceHostFactory as I was reading in the article shared by @Edmund Y: ServiceRoute + WebServiceHostFactory kills WSDL generation? How to create extensionless WCF service with ?wsdl.

In any case, I think I managed to resolve what I needed and I appreciate your help.

Community
  • 1
  • 1
Fernando Espinosa
  • 4,625
  • 1
  • 30
  • 37
  • 1
    `WebServiceHostFactory` is used to define "Web" (REST) endpoints. The "normal" `ServiceHostFactory` will take the endpoints from config (usually). And WCF Web Endpoints do not work with WSDL - see more info at http://blogs.msdn.com/b/carlosfigueira/archive/2012/03/26/mixing-add-service-reference-and-wcf-web-http-a-k-a-rest-endpoint-does-not-work.aspx – carlosfigueira Jul 12 '12 at 08:05