CRM 4 FilteredViews, LINQ & WCF
We decided to use FilteredViews instead of FetchXml for an internal project, but we ran into couple of problems. You can't access data from the FilteredViews using ASP.NET since it runs under NETWORK SERVICE (by default (app pool)), FilteredViews filter the data by Users.
If you set the <identity> settings on the WCF service you'll notice it has no effect, you need to tell WCF to run in asp compatibility mode, check this link for more details.
Impersonation needed for FilteredViews
- EXECUTE AS doesn't work, some forums suggested we enable DB_CHAINING, TRUSTWORTHY & grant NETWORK SERVICE Impersonate for each User, we decided to take a different route since these database changes are unsupported by Microsoft.
- Configuring the Application Pool to run as a different user gave a "Service Unavailable" error, changing the User that runs when an anonymous request comes into IIS didn't seem to work either.
Solution
web.config
<authentication mode="Windows" />
<identity impersonate="true" userName="..." password="..."/>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"></serviceHostingEnvironment>
</system.serviceModel>
*.svc.cs
Set this attribute on your service class
[AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]
That'll allow you to use FilteredViews in your asp.net application, as you can see there are downsides to this solution. Impersonating username/password is inside the web.config file (unencrypted), only allows us to filter by that user.
Check out LinqtoCRM on codeplex, this tool will be great once all the LINQ funtionality is implemented.