Reputation: 4825
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?
Upvotes: 2
Views: 5762
Reputation: 59601
Step-by-step instructions for .net newbs like myself:
Open your Web.config
file and ensure that the aspNetCompatibilityEnabled
is set to true:
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
Right click on the project, click Add->New Item. Find "Global Application Class". This will auto-generate a Global.asax file.
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)
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).
Upvotes: 3
Reputation: 4825
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.
Upvotes: 0
Reputation: 87228
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.
Upvotes: 5
Reputation: 1673
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
Upvotes: 1