1

I'm want to host both WCF 4 and MVC 3 in my C#.Net project. But when I add the service paths for WCF, Html.ActionLink starts creating a wrong url for MVC app. My route table is created as:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

RouteTable.Routes.Add(new ServiceRoute("api1/projects", new WebServiceHostFactory(), typeof(Projects)));
routes.MapRoute(
   "Default", // Route name
   "{controller}/{action}/{id}", // URL with parameters
   new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

Above route table creates the right access paths to both the WCF and MVC applications, but Html.ActionLink creates the edit links as

http://localhost:8000/api1/projects?action=Edit&controller=technology&id=2 

instead of

http://localhost:8000/technology/Edit/2

If I omit the line starting with RouteTable.Routes.Add, the ActionLink works as expected (and of course not the WCF). How can I add the WCF routes and make sure actionlink behaviour doesn't change?

Anne
  • 26,765
  • 9
  • 65
  • 71
  • Possible duplicate question: http://stackoverflow.com/questions/3570887/mvc2-routing-with-wcf-serviceroute-html-actionlink-rendering-incorrect-links – nemesv Nov 17 '11 at 22:12
  • Yes it was duplicate. The above question with http://stephenwalther.com/blog/archive/2008/08/07/asp-net-mvc-tip-30-create-custom-route-constraints.aspx solved my issue. – Ozgur Yogurtcu Nov 30 '11 at 02:48
  • See related topics: [About-using-WCF-RESTful-services](http://zayko.net/post/About-using-WCF-RESTful-services-together-with-ASPNET-MVC-projects.aspx) and [How-do-I-run-a-WCF-service-inside-an-MVC-website](http://blog.zoolutions.se/post/2010/10/30/How-do-I-run-a-WCF-service-inside-an-MVC-website-OR-Do-you-make-good-use-of-Linq.aspx) –  Feb 29 '12 at 19:29

1 Answers1

1

Try putting ServiceRoute registration after MapRoute.

Jakub Konecki
  • 45,581
  • 7
  • 87
  • 126