ServiceRoute + WebServiceHostFactory kills WSDL generation? How to create extensionless WCF service
- by Ethan J. Brown
I'm trying to use extenionless / .svc-less WCF services. Can anyone else confirm or deny the issue I'm experiencing?
I use routing in code, and do this in Application_Start of global.asax.cs:
RouteTable.Routes.Add(new ServiceRoute("Data", new WebServiceHostFactory(), typeof(DataDips)));
I have tested in both IIS 6 and IIS 7.5 and I can use the service just fine (ie my extensionless handler is correctly configured for ASP.NET). However, metadata generation is totally screwed up. I can hit my /mex endpoint with the WCF Test Client (and I presume svcutil.exe) -- but the ?wsdl generation you typically get with .svc is toast. I can't hit it with a browser (get 400 bad request), I can't hit it with wsdl.exe, etc. Metadata generation is configured correctly in web.config.
This is a problem of course, because the service is exposed as basicHttpBinding so that an old style ASMX client can get to it. But of course, the client can't generate the proxy without a WSDL description.
If I instead use serviceActivation routing in config like this, rather than registering a route in code:
<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
<serviceActivations>
<add relativeAddress="Data.svc" service="DataDips" />
</serviceActivations>
</serviceHostingEnvironment>
Then voila... it works.
But then I don't have a clean extensionless url. If I change relativeAddress from Data.svc to Data, then I get a configuration exception as this is not supported by config. (Must use an extension registered to WCF).
I've also attempted to use this code in conjunction with the above config:
RouteTable.Routes.MapPageRoute("","Data/{*data}","~/Data.svc/{*data}",false);
My thinking is that I can just point the extensionless url at the configured .svc url. This doesn't work -- the /Data.svc continues to work, but /Data returns a 404.
Anyone with any bright ideas?