[WSS]Use RPC protocol to access WSS v3 site
[WSS]Use RPC protocol to access WSS v3 site
The SharePoint Web Services Application Programming Interface (API) offers an extensive interface that helps to communicate remotely with SharePoint 2007. However, this SharePoint Web Services layer is not the only way to communicate remotely with SharePoint 2007. You can also use FrontPage or SharePoint RPC protocols. These protocols can be used to exchange information between a client computer and SharePoint 2007 and are probably the easiest way to make remote function calls.
WSS RPC protocol overview:
The FrontPage and SharePoint RPC protocols are layered on top of the HTTP protocol. FrontPage RPC method calls are sent to SharePoint 2007 via HTTP POST requests and handled by FrontPage Server Extensions. FrontPage and SharePoint RPC calls are directed to dynamic-link libraries (DLLs). The reason why has to do with the fact that a considerable part of WSS v3 is built in unmanaged code and most of the logic related to working with Sites and lists is provided through dynamic-link libraries (DLLs) containing unmanaged code. Amongst other things, these DLLs support SharePoint RPC and FrontPage RPC calls.
Just like webservice, WCF which use endpoints to expose remote service access points, sharepoint RPC service also expose several central endpoints. There are three FrontPage RPC end points:
n Admin.dll. The main responsibility of admin.dll is to administer SharePoint Sites.
n Author.dll. Author.dll has responsibilities like maintaining hyperlinks, generating and maintaining navigation bars and formatting pages.
n Shtml.dll. Shtml.dll adds functionality to SharePoint Sites, like managing interactive discussion groups, hit counters and search forms.
The access url is something like
https:// [server] / [site] /_vti_bin/_vti_adm/admin.dll
And sharepoint RPC uses the owssvr.dll endpoint, the url of which is as below:
https:// [server] / [site] /_vti_bin/owssvr.dll
Owssvr.dll provides much of the logic for working with Sites and lists and is able to interpret Collaborative Application Markup Language (CAML). CAML strings can be passed as arguments to SharePoint RPC method calls and plays an important role when calling SharePoint RPC methods via HTTP POST requests.
If you have interests in all the supported RPC methods and syntax, you can have a look at the reference in WSS V3 SDK:
Remote Procedure Call Protocol
https://msdn.microsoft.com/en-us/library/ms442469.aspx
Samples using RPC protocol to access WSS site/data:
In the following part, I’ll use some sample codes to demonstrate accessing sharepoint data via RPC protocol.
1. Use RPC http post to list documents on a site:
First, we use a winform client application with the following main UI to make simple frontpage RPC calls:
“Site Url” will hold the admin.dll endpoint’s full url, “Request Body” will hold the rpc request body and “Response Body” will display the response content. The “Send Request” button contains the following event handler code:
private void btnSend_Click(object sender, EventArgs e) { HttpWebRequest objRequest = (HttpWebRequest)HttpWebRequest.Create(txtSiteUrl.Text); objRequest.Method = WebRequestMethods.Http.Post; objRequest.Credentials = CredentialCache.DefaultCredentials; objRequest.Headers.Add("X-Vermeer-Content-Type","application/x-www-form-urlencoded"); objRequest.ContentType = "application/x-www-form-urlencoded";
StreamWriter sw = new StreamWriter(objRequest.GetRequestStream()); sw.Write(txtRequest.Text); sw.Close(); HttpWebResponse objResponse = objRequest.GetResponse() as HttpWebResponse; StreamReader sr = new StreamReader(objResponse.GetResponseStream()); txtResponse.Text = sr.ReadToEnd(); sr.Close(); objResponse.Close();
} |
It simply leverage the .NET webrequest component to make the HTTP post call, the response content will be html format content. You can save it into a htm file to view it.
2. Use http get method to access sharepoint RPC service:
In this example, we will use the dialogview method to show all *.docx files within a document library. This comes in handy if you want to share various documents across multiple SharePoint Sites.
The basic syntax of a SharePoint RPC call via a HTTP GET request looks like this:
The dialogview example shows how to call the SharePoint RPC dialogview method. The dialogview method takes the following parameters:
dialogview Method Parameters
Name |
Description |
dialogview |
The dialogview parameter determines the type of view that will be returned. Valid values are: FileOpen , FileSave and SaveForm . FileOpen mode shows an Open dialog box, FileSave mode shows a Save dialog box and SaveForm mode shows a Property form. |
location |
The location parameter specifies the Site-relative URL of a document library, folder or file. If you omit this parameter all document libraries within the SharePoint Site will be shown. |
FileDialogFilterValue |
The FileDialogFilterValue parameter allows you to filter file types. Examples of valid filter values are: *.doc, *.txt and *.htm. |
On a server called “MyWSSServer”, in a SharePoint Site called RPCSite, the SharePoint dialogview RPC call that shows all .docx files in the Shared Documents document library looks like this:
You can type the URL that calls the dialogview method directly into your browser which will display the result as below:
3. Use ASP.NET page/html form to issue PRC http request:
Here, we will call the “ExportList" SharePoint RPC method via both HTTP POST requests(within an .ASPX page using an HTML Form, JavaScript and the SharePoint FormDigest control). To try out the code you can simply add a new .ASPX page to the _layouts folder of your SharePoint virtual server.
Since there is no codebehind needed, we can directly use notepad to create an aspx page in the sharepoint 12 hive TEMPLATE/LAYOUTS folder(or a custom sub folder under it) and paste the following page content:
<%@ Page Language="C#" AutoEventWireup="true" Inherits="System.Web.UI.Page" %> <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <html> <head> <script type="text/javascript" language="JavaScript"> function InsertSecurityValidation(objForm) { var strFormDigest = '<SetVar Name="__REQUESTDIGEST">' + objForm.elements["__REQUESTDIGEST"].value + "</SetVar>\n"; var objPostBody = objForm.elements["PostBody"]; var objRegPattern = /<\/Method>/g; objPostBody.value = objPostBody.value.replace( objRegPattern, strFormDigest + "</Method>"); } </script> </head> <body> <form method="post" action="https://138129M:8888/RPCTest/_vti_bin/owssvr.dll" onsubmit="InsertSecurityValidation(this);"> <SharePoint:FormDigest ID="FormDigest1" 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" /> </form> </body> </html> |
Do remember to replace the “Action” url to your own WSS site’s RPC endpoint address. The “FormDigest” control is necessary since the RPC endpoint will validate the request via the formdigest value. If you’re programmatically issue such RPC request via WebRequest component, you can manually create an instance of the “FormDigest” control and call its “GetDesignTimeHtml” method to get a digest value.
#GetDesignTimeHtml
https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.formdigest_methods.aspx
Save the aspx page and then visit it in browser with its url in a certain WSS site, then paste the following CAML in the text area:
<Method ID="0,ExportList"> <SetList Scope="Request"> [list GUID] </SetList> <SetVar Name="Cmd">ExportList</SetVar> <SetVar Name="__REQUESTDIGEST">0x5987… ,18 May 2006 05:50:18 -0000</SetVar> </Method> |
Replace [list GUID] with the SharePoint list GUID (you can obtain it from web page interface for test). Press the Submit button. You may have time to notice that a form digest is added to the <Method> element within the text area.Examine the CAML response returned by owssvr.dll containing the list schema.
Other tips for using RPC protocol to access sharepoint site:
Frankly speaking, the RPC protocol is not used that much since the existing WSS Object Model and webservice interface have been quite enough for most development cases. Just in case you will have to do lots of sharepoint development via RPC protocol, there are some tools which can help a lot for inspecting and troubleshooting the RPC request/response communications.
Fiddler
HTTP monitor tools such as Fiddler make debugging applications issuing FrontPage and SharePoint RPC method calls easier.
1. Open a command prompt and type the following: Fiddler. This starts the Fiddler – HTTP Debugging Proxy screen. Fiddler is an HTTP monitoring tool.
2. Ensure that Fiddler captures HTTP traffic by clicking File. The Capture Traffic F12 option should be checked.
3. In the left tool pane, click on the request to /services/version.asmx located on https://www.fiddlertool.com.
4. In the upper right tool pane, click on Session Inspector > Raw.
5. In the lower left tool pane, click the Raw tab.
Setting Fiddler in this mode makes it easy to monitor HTTP traffic.
Sharepoint Designer
Since Sharepoint Designer use PRC protocol underlyingly, you can learn a lot from opening and interacting with a SharePoint Site in Microsoft Office SharePoint Designer and analyze the FrontPage RPC calls with an HTTP monitor tool on the way.
Comments
Anonymous
September 07, 2010
Actually, i am using RPC to connect to SharePoint to retrive all the documents along with its metadata. It worked fine with SharePoint2007, but when i try to use FrontPage RPC method 'list versions' which is used to get all versions of a document in SharePoint 2010, it results in a message saying 'list versions not supprted'. Is ther any specific reason why 'list versions' method of FromPageRPC not supported in SharePoint 2010 while other methods like 'Get document' still working.Anonymous
March 25, 2015
I am using Author.dll to upload a document in SharePoint Library in chunks through FPSE RPC. My code is working perfectly on SP2010 (single and multi server Farm). I tried same code on SP2013 single server Farm and its working fine as well. But on SP2013 Multi server Farm i am always getting "Internal Server Error 500". Can you provide me any help in this regard?