WCF Service Hosting in an MVC Application Out of Scopes

I have an MVC project to which I have added a folder to the WCF root directory. In this folder, I created a WCF service called CustomFunctions . When I try to start the service, I get the following error:

Error: it is not possible to get metadata from http://localhost/Viper/WCF/CustomFunctions.svc ... Metadata contains a link that cannot be resolved:

With additional description:

Cannot find the type "Viper.WCF.CustomFunctions" provided as the value of the Service attribute in the ServiceHost directive or provided in the system.serviceModel / serviceHostingEnvironment / serviceActivations configuration item.

Yesterday I received this error and spent some time searching the Internet. This led me to changes in my Web.config as well as in my Global.asax.cs. One day, he started working, and I stopped. However, when I returned this morning, he did not work again and again. Nothing new was added, and no code was changed during this time.

I added the following to my Web.config:

 <system.serviceModel> <services> <service behaviorConfiguration="WCFBehavior" name="Viper.WCF.CustomFunctions"> <endpoint address="" binding="wsHttpBinding" contract="Viper.WCF.ICustomFunctions"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> <host> <baseAddresses> <add baseAddress="http://localhost/Viper/WCF/CustomFunctions/" /> </baseAddresses> </host> </service> </services> <behaviors> <serviceBehaviors> <behavior name="WCFBehavior"> <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" httpGetUrl=""/> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> </system.serviceModel> 

And this is for my Global.asax.cs :

 public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.svc/{*pathInfo}"); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults new { controller = "^(?!CustomFunctions).*" } ); routes.Add(new ServiceRoute("CustomFunctions", new ServiceHostFactory(), typeof(CustomFunctions))); } 

Can anyone help me? Here I have all the ideas.

+4
source share
1 answer

I understood the problem. First of all, I skipped part of the path to a function that registers my routes. After I installed this path, I was able to open my wsdl in my hosting environment. However, this ruined the default routing for my areas. Therefore, for those who have this problem in the future, here is my solution:

 public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.svc/{*pathInfo}"); routes.MapRoute( "CustomFunctions", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "CustomFunctions", action = "Index", id = UrlParameter.Optional }, // Parameter defaults new { controller = "^(?!CustomFunctions).*" } ); routes.Add(new ServiceRoute("CustomFunctions", new ServiceHostFactory(), typeof(CustomFunctions))); routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); // Had to do some special stuff here to get this to work using a default area and no controllers/view in the root routes.MapRoute( name: "Default", url: "{area}/{controller}/{action}/{id}", defaults: new { area = "", controller = "Home", action = "Index", id = UrlParameter.Optional }, namespaces: new string[] { "Viper.Areas.Home" } ).DataTokens.Add("area", "Home"); } 

I indicated my own route primarily so that when I navigated to the specified URL, it will show my .svc file. I call this method from my ApplicationStart method in Global.asax.cs. I also had to create a separate controller and view my user-defined functions in my home area so that it could distinguish between my default route and my CustomFunctions settings and indicated what was in my route map as shown above. Therefore, when I go to localhost \ Viper, it will find the route specified in my default map, and when I go to localhost \ Viper \ CustomFunctions, it will find the route to my .svc file. IgnoreRoute basically does this, so you don’t have to put the file extension at the end of the URL when your page is called. Therefore, instead of CustomFunctions.svc, I specify only CustomFunctions. Make sure you add the System.ServiceModel.Activation assembly and use the instructions for your project in doing so.

Thank you all for your help. Hope this helps another bad lost soul.

+4
source

All Articles