SharePoint 2010 : Sandbox Solution Part 4 Full Trust Proxy
Full Trust Proxy: Sandboxed solution to execute an action that is ordinarily not available to sandboxed solutions.
One of these techniques is to create a special kind of operation that runs in a full trust process, but that can be called from a sandboxed solution. The operation is deployed as a farm solution by a farm administrator who trusts it and is prepared to let sandboxed solutions call it. These operations are called full-trust proxy operations. (Microsoft Definition).
- Full trust proxy is a farm solution that runs Outside the Sandbox Solution.
- Sandbox Solution uses that assembly and call Execute method to perform the operation which was out the scope of sandbox solution. The class inherits from SPProxyOperation.
- Full trust Proxy Input parameters used as serialize class (used “Serializable” attribute) that inherits from SPProxyOperationArgs
- Register proxy with User Code Service during Feature activation.
- Referenced the assembly in Sandbox solution use it.
- Create an Empty SharePoint Farm Solution let’s Call it "AddlinkdemoProxy". Go to properties AssemblyInfo.cs file Add new attribute [assembly: AllowPartiallyTrustedCallers()]
- Add new Class file name it CustomAddLinkProxy.cs. Make it public and inherits SPProxyOperation. Override Execute Method it takes SPProxyOperationArgs as argument. For passing SPProxyOperationArgs we need to create a class with Serializable attribute. Create the class parameters that will be used in Sandbox Solution.
- Add Code in feature activation to register our custom feature activity.
- Add new project and set as sandbox solution and proxy assembly to that project and use this proxy in sandbox to run the farm code.
Download the full code.