Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

rest - How to remove the ".svc" extension in RESTful WCF service?

In my knowledge, the RESTful WCF still has ".svc" in its URL.

For example, if the service interface is like

[OperationContract]
[WebGet(UriTemplate = "/Value/{value}")]
string GetDataStr(string value);

The access URI is like "http://machinename/Service.svc/Value/2". In my understanding, part of REST advantage is that it can hide the implementation details. A RESTful URI like "http://machinename/Service/value/2" can be implemented by any RESTful framework, but a "http://machinename/Service.svc/value/2" exposes its implementation is WCF.

How can I remove this ".svc" host in the access URI?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I know this post is a bit old now, but if you happen to be using .NET 4, you should look at using URL Routing (introduced in MVC, but brought into core ASP.NET).

In your app start (global.asax), just have the following route configuration line to setup the default route:

RouteTable.Routes.Add(new ServiceRoute("mysvc", new WebServiceHostFactory(), typeof(MyServiceClass)));

then your URLs would look like this:

http://servername/mysvc/value/2

HTH


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...