How to: Create a REST Service Proxy
|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.|
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
- In Solution Explorer, right-click the project node, and then click Add Service Reference.
- In the Add Service Reference dialog box, in the Address text box, type the URL of the REST service, and then click Go.
Note: The REST interface is exposed on every SharePoint site. The URL of the REST service is <site URL>/_vti_bin/ListData.svc.
- 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.
Note: The REST service will always be named <sitename>DataContext, where <sitename> is the name of the SharePoint site.
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.
- In the code-behind for your Silverlight control, instantiate the data context class, using the fully qualified URL of the REST service.
Note: You should declare and instantiate the data context at the class level so that it is available to all the methods on your control.
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.