Fault Contract’1 was unhandled by user code: Solved

For a training purpose I was trying a basic demo on fault contract in WCF and to be surprised I Got below error while throwing FaultException.

clip_image002

It’s not that 1st time I was working on Fault Contract but this error was irritating. After some investigation I found there was some issue in visual studio 2013 setting. So to solve this in Visual Studio go to Tools->Options.

In General tab from Debugging section uncheck following options,

  • Enable the exception assistant
  • Enable Just My Code
  • image

    Changes in Visual Studio setting should solve the problem. Keep in mind that above error can occur due to other reasons also. Visual setting debugging option may be one way to solve above said error. I hope you find it useful. Thanks for reading.

    About these ads

    Publish WCF Service in Local IIS on Visual Studio 2013

    Long back I wrote a blog post Step by Step hosting WCF Service in IIS 7.5 . In this post I used Visual Studio 2012 as I remember. Today I was trying to host WCF in local IIS in Visual Studio 2013 and found it is surprisingly easy to host WCF Service in IIS 2013 in Visual Studio 2013.

    Let us assume you have created a WCF Service. Now to publish it in local IIS right click on project and from context menu select Properties.

    In Properties select Web tab. In Web tab from Servers drop down select local IIS.

    clip_image002

    Next click on Package/Publish Web tab and from Items to deploy drop down select Only Files Needed to run this application.

    clip_image004

    Now when you press F5 and run application WCF Service will be hosted in local IIS.

    clip_image006

    As you see now hosting in IIS is super easy. I hope you find this post useful. Thanks for reading.

    Solved Access-Control-Allow-Origin Error in WCF REST Service

     

    Recently I was working on a JSON based WCF REST Service. It was a simple service performing CRUD operation. When I tried to consume service from a web based client, got following errors in browser console.

    clip_image002

    Error message was, No Access-Control-Allow-Origin header is present on the required resource. Since service was running on different server and it was not configured to accept request from any origin. This error can be resolved by enabling CORS: Cross Origin Resource Sharing for the service.

    image

    You can enable CORS on service hosted on IIS or IIS Express by adding following configuration in config file.

    clip_image002[6]

    We have added a custom header that allow Access-Control-Allow-Origin value to *. By setting it * , we are allowing request from any origin to access the service. So to solve error I went ahead and added following configuration in web.config of service under system.webServer section,

    
    <system.webServer>
        
        <httpProtocol>
          <customHeaders>
            <add name="Access-Control-Allow-Origin" value="*" />
          </customHeaders>
        </httpProtocol>    
        
        <modules runAllManagedModulesForAllRequests="true"/>  
        <directoryBrowse enabled="true"/>
      </system.webServer>
    
    
    

     

    After adding above configuration you should able to access service in client side codes like JavaScript. I hope this post is useful.