Friday, 4 June 2010

Deployment Error on Sandbox Solution while deploying web part


Error occurred in deployment step 'Activate Features': Timeout occurred while running the SharePoint Sandboxed Code service. This service is required to run sandboxed solutions in SharePoint. Please ensure the service is configured correctly in SharePoint


Goto Services and start "Sharepoint 2010 User Code Host" Service

Wednesday, 2 June 2010

Calling a Web Service in Sandbox Solution

In order to call a web service in sandbox environment following steps should be followed.

Note: Assuming you already have created the web service and deployed it in IIS

1. Create a class library project and which is derived from “SPProxyOperation” (Microsoft.SharePoint.UserCode namespace).

Code Snippet

class ProxyProvider : SPProxyOperation
public override object Execute(SPProxyOperationArgs args)


(args != null)

ProviderSoapClient client = new ProviderSoapClient();

ProviderArgs providerArgs = args as ProviderArgs;

return client.GetDepartmentByCode(providerArgs.DeptCode);




return "Error while calling Web Service...";




2. Create another class which should be used for passing arguments to the SPProxyOperation class

Code Snippet


public class ProviderArgs : SPProxyOperationArgs
public int DeptCode
public ProviderArgs(int code)
this.DeptCode = code;

3. Argument class must have “Serializable” attribute.

4. Implement Execute method of SPProxyOperation class.

5. Attach below attribute with the assembly


6. Make sure assembly is strongly named.

7. Deploy the assembly in GAC using GACUTIL(Since drag and drop assembly gives access denied error).

8. Register the assembly in Sharepoint

To register a assembly in Sharepoint “Power Shell” can be used.

Write below scripts in a .ps1 file and run from power shell

Param($assemblyName, $typeName)

$userCodeService = [Microsoft.SharePoint.Administration.SPUserCodeService]::Local

$proxyOperationType = new-object -typename Microsoft.SharePoint.UserCode.SPProxyOperationType -argumentlist $assemblyName, $typeName



9. Since this is full trust proxy class so it would run under “SPUCWorkerProcessProxy.exe” so add the web service related configuration setting in SPUCWorkerProcessProxy.exe.config file which can be found under “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\UserCode” folder.

10. Now you are ready to call the web service method via Proxy operation class. Use below method to call the web service from your Sandbox Solution.

SPUtility.ExecuteRegisteredProxyOperation("AssemblyName, Version=, Culture=neutral, PublicKeyToken=fffdd72d4537ce50", "NameSpace.ClassName", new ArgumentClass(Argument));

Query List/Document Library in Specific Folder

To query SharePoint List or Document Library in specific Folder “ FolderServerRelativeUrl ” as part of the CAML Query Code Snippet ...