BizTalk Error: Failed to grant permission to execute. (Exception from HRESULT: 0x80131418)

Here is an issue I ran into for BizTalk 2009 when using the WCF-BasicHttp or WCF-WSHttp adapter. 
 
I received the following error:
The adapter "WCF-WSHttp" raised an error message. Details "System.Security.Policy.PolicyException: Failed to grant permission to execute.
 
What was I doing?
What I was trying to do is expose a schema as a web service endpoint so that any calls to that service would dump that message straight to the message box.  Now … not wanting to expose my internal schema I created a schema definition especially for this service and a corresponding map to map it to my canonical/internal schema.  Deployed the solution.
 
Next, I used the handy BizTalk WCF Service Publishing Wizard to create the .svc and ports, etc.  I then updated the Receive Port to run the map.  When I tested the endpoint I got the above error.  I then removed the map and the test ran succesfully (albeit with my intended map). 
 
What the heck was happening?
Well … as luck would have it I had quickly ramped up this virtual server environment and put the portal on port 80 which meant WSS was running on port 80.  Upon inspecting the .NET Trust Level for my web application it was set to WSS_Minimal!!! Arggg!  I had spent way too much time on this one!
 
What was the fix?
Just some things to remember when setting up a web application to run a service into BizTalk:
  • Create a separate App Pool running as a user that has permission to the BizTalk Isolated Host (I just ran it as my BizTalk Iso service account as a shortcut)
  • Make sure this app pool is running as classic mode and not integrated mode
  • CHECK THE TRUST LEVEL to make sure it is appropriate … in my case I just set it to Full Trust to get it through my test
  • Don’t for get to enable the receive location, it is not enabled by the wizard … you couldn’t imagine how many times I forgot to do this while trying to figure out why my darn service isn’t working again!

Well … hope this helps someone else!