How to: Post SharePoint Foundation RPC Methods

Applies to: SharePoint Foundation 2010

You can use URL Protocol in combination with Collaborative Application Markup Language (CAML) and SharePoint Foundation Remote Procedure Call Protocol (RPC) to post requests to a front-end Web server that is running Microsoft SharePoint Foundation 2010. Use the CAML Method element to post a single request, or a Batch element containing multiple Method elements to post multiple requests, through the post body of a form in an .ASPX page. The following programming task shows how to create a form for posting requests.

To create a form for posting requests

  1. Create an .aspx page and add a page directive, such as the following, that registers the Microsoft.SharePoint.WebControls namespace for the server control.

    <%@ Register Tagprefix="SharePoint" 
      Assembly="Microsoft.SharePoint, Version=, 
      Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>


    You can obtain the PublicKeyToken value for the current SharePoint Foundation 2010 deployment from the default.aspx file in the path Local_Drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\SiteTemplates\sts, or from information provided for the Microsoft.SharePoint assembly at Local_Drive:\%WINDOWS%\assembly in Windows Explorer.

  2. Add the following script block to automatically insert the FormDigest control into each Method element when the form is submitted.

    <script type="text/javascript" language="JavaScript">
    function InsertSecurityValidation(oForm)
        var sFormDigest = '<SetVar Name="__REQUESTDIGEST">' + 
          oForm.elements["__REQUESTDIGEST"].value + "</SetVar>\n";
        var oPostBody = oForm.elements["PostBody"];
        var rePattern = /<\/Method>/g;
        oPostBody.value = oPostBody.value.replace(rePattern, 
            sFormDigest + "</Method>");
  3. Create a form in the .aspx page such as the following, where the action attribute contains the URL command that is posted to the server.

    <form method="post" 
      <SharePoint:FormDigest runat="server" />
      <input type="hidden" name="Cmd" value="DisplayPost" />
      <textarea rows="18" name="PostBody" cols="72"></textarea>
      <input type="submit" value="Submit" />
      <input type="reset" value="Reset" />

    The form uses the DisplayPost method to request that the server render whatever CAML is contained within the post body.

  4. Open the form in the browser and insert a block of code like the following into the post body, which uses the Batch element to post multiple RPC methods for adding two announcements to an announcements list:

    <ows:Batch Version="" OnError="Return">
      <Method ID="A1">
        <SetVar Name="ID">New</SetVar>
        <SetVar Name="Cmd">Save</SetVar>
        <SetVar Name="urn:schemas-microsoft-com:office:office#Title">
            New Program Manager</SetVar>
        <SetVar Name="urn:schemas-microsoft-com:office:office#Body">
            Congratulations to Jane for her promotion!</SetVar>
        <SetVar Name="urn:schemas-microsoft-com:office:office#Expires">
      <Method ID="A2">
        <SetVar Name="ID">New</SetVar>
        <SetVar Name="Cmd">Save</SetVar>
        <SetVar Name="urn:schemas-microsoft-com:office:office#Title">
            Sales rise by 10%</SetVar>
        <SetVar Name="urn:schemas-microsoft-com:office:office#Body">The
            accounting department has released its quarterly report. 
            Check it out!</SetVar>
        <SetVar Name="urn:schemas-microsoft-com:office:office#Expires">

Compiling the Code

The Batch element must contain a Version attribute that specifies the version of SharePoint Foundation that the server is running. Each SetList node must specify the GUID of the list.

When the form is submitted, this sample adds two records to an announcements list.


If security validation is enabled on the server, which is true by default in SharePoint Foundation, then a FormDigest server control must be added within the form. For information about this control and security validation, see Security Validation and Making Posts to Update Data. Each Method element used in a post must have a form digest specified; otherwise, the post will not pass security validation.