Sandbox Solution and Full trust Proxy

To make sure your sandbox solution can run in Sharepoint server – change the Microsoft.Sharepoint.DLL to referene the sandbox’s version:

But need to change it back before deployment.

Sandbox has restricted access/resurce, but can break out of the box by using a full trust proxy:

1. Decide what you want to do in the full trust proxy, and write it in a class that inherits from Microsoft.SharePoint.Usercode.SPProxyOperation
2. Decide what arguments you need to pass to this proxy – must be serzliazble object that inherits from Microsoft.Sharepoint.Usercode.SPProxyOperationArgs
3. Compile the class into a DLL put it into GAC
4. Register it with Sharepoint.
5. Consume the proxy in a snadbox solution!

Step 1: Create the SharePoint Project. In this step, you create a Visual Studio 2010 project that you can use to deploy and test your sandbox proxy.
Step 2: Create the Proxy Arguments Class. In this step, you create a serializable type that you can use to pass arguments from the sandbox to the sandbox proxy.
Step 3: Create the Proxy Operation Class. In this step, you create a class that contains the full-trust logic that you want to expose to sandboxed solutions.
Step 4: Register the Proxy Operation. In this step, you register your proxy operation with the user code service in order to make your operation available to sandboxed callers.
Step 5: Use the Proxy Operation from the Sandbox. In this step, you call your proxy operation from a sandboxed solution.

in the proxy argument class, you would define the name of the proxy operation class.

How to register? In the FeatureActivated:

SPUserCodeService userCodeService = SPUserCodeService.Local;
var simpleOperation = new SPProxyOperationType(


Use the Proxy from your sandbox code:

// Create an args object, and assign value
var proxyArgs = new SimpleProxyArgs();
proxyArgs.ClientName = “Adventure Works”;
proxyArgs.ClientID = 1;

// Pass the args object as a parameter
var result = SPUtility.ExecuteRegisteredProxyOperation(

// Cast the result
double availableCredit = (double) result;

Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: