ServiceRoute + WebServiceHostFactory kills WSDL generation? How to create extensionless WCF service with ?wsdl

前端 未结 2 1010
我在风中等你
我在风中等你 2020-11-29 07:22

I\'m trying to use extension-less / .svc-less WCF services. Can anyone else confirm or deny the issue I\'m experiencing?

I use routing in code, and do this in Appli

相关标签:
2条回答
  • 2020-11-29 08:03

    I have a the same issue. Your solution works on my code. I just changed the Global.asax like this:

    <%@ Application Language="C#" %>
    <%@ Import Namespace="System.Web.Routing" %>
    <%@ Import Namespace="System.ServiceModel.Activation" %>
    <%@ Import Namespace="System.ServiceModel.Web " %>
    
    <script RunAt="server">
        void Application_Start(object sender, EventArgs e)
        {
            RegisterRoutes(RouteTable.Routes);
        }
    
        private void RegisterRoutes(RouteCollection routes)
        {
            routes.Add(new ServiceRoute("URLWithoutSVC", new WebServiceHostFactory(), typeof(Service))); 
       }
    </script>
    

    To

    <%@ Application Language="C#" %>
    <%@ Import Namespace="System.Web.Routing" %>
    <%@ Import Namespace="System.ServiceModel.Activation" %>
    <%@ Import Namespace="System.ServiceModel.Web " %>
    
    <script RunAt="server">
        void Application_Start(object sender, EventArgs e)
        {
            RegisterRoutes(RouteTable.Routes);
        }
    
        private void RegisterRoutes(RouteCollection routes)
        {
            routes.Add(new ServiceRoute("URLWithoutSVC", new ServiceHostFactory(), typeof(Service))); 
       }
    </script>
    
    0 讨论(0)
  • 2020-11-29 08:12

    Wow, do I feel dumb.

    I should have been hosting my service with ServiceHostFactory, NOT WebServiceHostFactory.

    As soon as I moved back to code from config... and swapped to this line of code:

    RouteTable.Routes.Add(new ServiceRoute("Data", new ServiceHostFactory(), typeof(DataDips)));
    

    I was in business with an extensionless URL serving up WSDL and help pages.

    It's too bad I wasted so much time on this. It was an accident that I was using WebServiceHostFactory, but there's no disclaimer on the factory page in MSDN about the reduced functionality. (I would argue that removing WSDL makes sense, but removing the Help pages does not as they could simply provide an attribute in config to rename the 'Help' page should there be a REST operation with that name... sigh).

    There is a note in the WebServiceHost docs http://msdn.microsoft.com/en-us/library/system.servicemodel.web.webservicehost.aspx

    0 讨论(0)
提交回复
热议问题