Export (0) Print
Expand All
0 out of 2 rated this helpful - Rate this topic

How to: Create a REST Service Proxy

Overview

The Microsoft® SharePoint® Foundation REST interface provides a simple and robust mechanism for accessing SharePoint list data from external applications. Although REST services can be accessed directly by using HTTP verbs, and manipulated by using either Atom or JavaScript Object Notation (JSON), you can also generate a Windows Communication Foundation (WCF) Data Services client proxy for the REST service. This allows developers to interact with the REST service by using strongly typed objects and a consistent development model.

Ff798366.note(en-us,PandP.10).gifNote:
This how-to topic assumes that you have used the Microsoft Visual Studio® 2010 development system to create a solution that contains a Microsoft Silverlight® application project, and that you have installed and configured ADO.NET Data Services in your development environment, as described in the SharePoint 2010 installation prerequisites.

Steps

This procedure describes how to use Visual Studio 2010 to create a service proxy for the SharePoint REST interface. You can use this service proxy to interact with the REST service from client-side code. This procedure assumes that you have already created a Visual Studio 2010 project.

To generate a service proxy

  1. In Solution Explorer, right-click the project node, and then click Add Service Reference.
  2. In the Add Service Reference dialog box, in the Address text box, type the URL of the REST service, and then click Go.
    Ff798366.note(en-us,PandP.10).gifNote:
    The REST interface is exposed on every SharePoint site. The URL of the REST service is <site URL>/_vti_bin/ListData.svc.

    Ff798366.741a1afb-ab0c-4bda-af2d-fe932b2aeefb(en-us,PandP.10).png

  3. In the Services list box, select the REST service. In the Namespace text box, type the friendly name for the service, and then click OK.
    Ff798366.note(en-us,PandP.10).gifNote:
    The REST service will always be named <sitename>DataContext, where <sitename> is the name of the SharePoint site.

    Ff798366.b9f7a0f3-ecf9-42ab-a8e4-1566ceac6948(en-us,PandP.10).png

    When you click OK, Visual Studio creates the service proxy classes. You can now use the service proxy to interact with the REST interface from your code.

  4. In the code-behind for your Silverlight control, instantiate the data context class, using the fully qualified URL of the REST service.
    Ff798366.note(en-us,PandP.10).gifNote:
    You should declare and instantiate the data context at the class level so that it is available to all the methods on your control.

    PartsDataContext context = new PartsDataContext(new 
      Uri("http://localhost/sites/sharepointlist/_vti_bin/listdata.svc"));
    
    

You can now use the data context to create and submit queries to the REST interface. For more information about using the service proxy with the REST interface, see the Client Reference Implementation.



Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.