Thursday, December 30, 2010

WCF Errors with IIS7 with .Net Framework 4.0

WCF Errors with IIS7 with .Net Framework 4.0 

When I start hosting WCF service on the IIS7 then I got following errors and I spend enough time to resolve this, following error could be caused by different reason but I described the reason and solution which I faced. I was using Visual Studio 2010 with .Net framework 4.0 and IIS7.  

Error-1: HTTP Error 404.17 - Not Found
The requested content appears to be script and will not be served by the static file handler.

Cause
WCF service developed on different .NET framework (V4.0) and Application Pool set in different version (V2.0).
Solution
Go to the IIS 7 and select Application Pools à right click on your application and change the .NET Framework version to V4.0. (Change the v2.0 to v4.0 in Application Pool)

Error-2: HTTP Error 500.19 - Internal Server Error

The requested page cannot be accessed because the related configuration data for the page is invalid.


Cause
This error occurs when you application deployed on the different version of .NET and Web.config has different version mentioned.
Like: Application Pool running on .Net 4.0 and Web.Config includes .Net 3.5
Solution
Go to the application project à right click and go to "Property Pages"à Build tab and Set the application Target Framework to .Net Framework 4.0.
Another quick fix, change application pool set to 2.0 as default.
Error-3: No protocol binding matches the given address 'http://localhost/IISHostedService/MyService.svc'. Protocol bindings are configured at the Site level in IIS or WAS configuration.

 <endpoint address="http://localhost/IISHostedService/MyService.svc" binding="wsHttpBinding" contract="IMyService">
Solution
Remove this address URL from Web.config, because this is already configured in IIS.
Go to the web.config and change in the Services section like below
<endpoint address="" binding="wsHttpBinding" contract="IMyService">


Error-4: Metadata publishing for this service is currently disabled.


There are couples of help available on internet and on the site page where this error displays. But for that was not the problem

Cause

Normally this error occurs when "httpGetEnabled" is false in Web.config 
check your web.config <serviceMetadata httpGetEnabled="true">


But for me the problem was, I created one folder explicitly in “C:/inetpub” called ‘MyFolder’ and then from the visual studio I created WCF service on that folder choosing

Web location: File System and File created on “C:/inetpub/MyFolder”.


Now when I deploy my WCF service and try to access then its throws following error “
Metadata publishing for this service is currently disabled.

Solution

DONOT create any folder explicitly on “C:/inetpub” and while creating new WCF service choose following option

Web location: HTTP and File created on “http://localhost/MyFolder”.