Saturday, April 9, 2011

Problem saving/accessing files in a folder in WCF

Impact: Not able to save and access files to and from a folder of your choice in WCF application

Solution: Like a web service in ASP.NET if you try to use HttpContext.Current.Request.MapPath() to save the file to a directory of your choice or to create an absolute URL of the file, when you try to run you application you will end up with exceptions. You can get rid of these exceptions by enabling the ASP.NET compatibility mode in WCF application. To enable compatibility mode follow the steps mentioned below.

  1. Open Web.config file and find the node <system.serviceModel>.
  2. Inside <system.serviceModel> nodes write: <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />.
  3. Now in the class which extends you service interface, add the following attribute at the top: [AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]

No comments:

Post a Comment