While working on a recent project I had to create an InfoPath 2010 form which took some parameters and queried CRM to retrieve additional details. At first I tried to setup a new Web Service data connection but I kept getting errors so instead decided to handle it all in code on the page load.
Anyone who has developed an InfoPath form with code behind knows it can be a very frustrating process to write the code and debug issues. In addition the deployment process can take a while which results in the whole processes being very time consuming. To get around this I decided there was no reason why I couldn’t create a Windows Forms application and use it as a test harness for the code.
I created a new Windows Forms Application, designed my UI, added my CRM references and implemented the code. After a few iterations of testing I was successfully able to pull information back from a development CRM instance. I then moved my code into the InfoPath form, made the required changes and deployed it. As with all development I was hopeful this would work first time around but it didn’t . I looked at the ULS logs on the SharePoint server and noticed the error below.
System.Security.SecurityException: Request for the permission of type ‘System.Net.WebPermission, System, Version=22.214.171.124, Culture=neutral, PublicKeyToken=b77a5c561934e089’ failed.
After much looking around and testing I was unable to establish what was causing the issue. I checked my original application and it worked and compared the code with the InfoPath version but I was unable to see any major differences. After checking the code and when I was happy it was not a code issue my attention turned to what security issues could be causing this error. Immediately it suddenly occurred to me that I hadn’t changed the Security Level option in the form settings, steps to adjust InfoPath Security settings. To be honest this probably should have been my first port of call but fingers cross this article will help someone else or at least act as a reminder for me