WCF web service using the WebScriptServiceHostFactory
I am starting a new project using WCF so that I can use jQuery to make AJAX calls to the server. I have had all kinds of issues with configuring WCF in the past so I decided to do some new research to see if the level of documentation for WCF in VB had improved. Unfortunately WCF documentation to me is still as cloudly as when it was released as a CTP...
However I rediscovered the WebScriptServiceHostFactory and decided to give it a try. From what I gathered from several sources, I should be able to use the WebScriptServiceHostFactory in my .svc file and not have to worry about trying to go through the ABC's of WCF, (Pun intended).
I built a project that connects to a SQL Server and by way of LinqToSql and returns a dataset. I included the WebScriptServiceHostFactory and and also added the
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
to the web.config. But when I 开发者_StackOverflow社区run it I get the dreaded "Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service" error message that plagued me so much when I first started to play with WCF.
I rewrote the function to just return a string instead of connecting to a database, etc, just to see if it would work, but I got the same thing.
So the question is, besides adding the factory to the .svc file and the previously mentioned serviceHostingEnviroment option to the web.config, what am I doing wrong???
I have tried checking & unchecking "Enable anonymous access" in the directory security tab in IIS as well. (I have Integrated Windows and Digest Windows Authentication checked).
As always, Thanks!!!
Those articles and blog posts might be helpful to get you started:
- jQuery AJAX all to WCF REST service
- Access an AJAX Enabled WCF Service using ASP.NET and Client Script
- Creating WCF Services for ASP.NET AJAX
- How To Consume WCF Using AJAX Without ASP.NET
- Ron Jacobs on how to create an AJAX-enabled WCF service (Endpoint TV)
Also for your IIS hosting problem, Dominick Baier writes in Hosting WCF Services in ASP.NET - The Survival Guide:
IIS Authentication Settings
Another thing I noticed is, that WCF requires to enable anonymous authentication for the .svc files in IIS (regardless of WCF authentication settings). If you drop a .svc file into an existing ASP.NET application that uses Windows authentication you will see this error message:"Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service."
You have to individually enable anonymous access for the .svc files to make it work.
So either you can follow this practice, or you could optionally also self-host the WCF service instead of relying on IIS - that might solve a boatload of problems at once and give you more control over your hosting.
精彩评论