Search code examples
visual-studio-2010wcfc#-4.0silverlight-5.0

WCF not working when debugging in visual studio but works in IE


I have a WCF that is hosted in an ASP.NET application. Suddenly, the WCF service has stopped working when i debug it in visual studio 2010. When i try to access the service, it throws the below exception.

CommunicationException was unhandled by user code. The remote server returned an error: NotFound

I have WCF tracing enabled but no errors are being logged.

The strange bit is that if i deploy the code to my QA server and access the application, the service works fine, so the code looks like not the problem.

If i also get the source code currently running in production successfully & try debugging it in my dev environment, it fails with the same error i mention above.

Any one have an idea what could be messed up in my dev environment?. I have tried both IE, Firefox & Chrome & the results are the same.


Solution

  • I after a very long debugging involving deleting Bin & obj folders and lots of rebuilds, i finally got this WCF service working again.

    First, i suspected the service could be corrupted somehow, so i tried to update the service reference in my silverlight application but was bumped with the following error.

    There was an error downloading 'http://localhost/mySite/Webservice/GetData.svc'. The request failed with HTTP status 404: Not Found. Metadata contains a reference that cannot be resolved: 'http://localhost/mySite/Webservice/GetData.svc'. The remote server returned an unexpected response: (405) Method Not Allowed. The remote server returned an error: (405) Method Not Allowed.

    I then browsed to the physical folder path to confirm if really my .svc file was there and indeed as expected, the file was there.

    Trying to Browse to the path http://localhost/mySite/Webservice/GetData.svc in my browser bumped me with another error below.

    HTTP Error 404.7 - Not Found The request filtering module is configured to deny the file extension.

    Most likely causes: Request filtering is configured for the Web server and the file extension for this request is explicitly denied.

    This made me start thinking that suddenly, IIS 7.0 has decided to block access to my .svc files. I then added fileExtension=".svc" mimeType="application/octet-stream" to IIS, restart IIS but got the same error.

    I then read on some blog i cant remember about adding <add fileExtension=".svc" allowed="true" /> under <requestFiltering> tag in file applicationHost.config located at C:\Windows\System32\inetsrv\Config, still nothing changed. Tried adding <mimeMap fileExtension=".svc" mimeType="application/octet-stream" /> under serverSideInclude in the same file, again with no luck.

    Tried this http://www.adamwlewis.com/articles/iis-7-not-serving-files-4047-error still with no luck.

    The following 2 steps are i think what resolved the issue.

    1. I added a mapping for the SVC extension to ASP.NET by running ServiceModelReg.exe -i from C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation

    Browsed to my .svc file in the browser and this time it looked like i had made some progress but still, i had one more error to overcome . The is bellow.

    Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

    1. I resolved the above error by registering the correct version of ASP.NET using the ASP.NET IIS Registration Tool (aspnet_regiis.exe,) as described in the link below

    https://msdn.microsoft.com/en-us/library/hh169179(v=nav.70).aspx

    At this point my service was back to normal as it had always been. I still haven't figured out what messed up my development machine.