{"id":1603,"date":"2009-10-21T11:21:00","date_gmt":"2009-10-21T11:21:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/odatateam\/2009\/10\/21\/using-data-services-over-sharepoint-2010-part-1-getting-started\/"},"modified":"2009-10-21T11:21:00","modified_gmt":"2009-10-21T11:21:00","slug":"using-data-services-over-sharepoint-2010-part-1-getting-started","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/odata\/using-data-services-over-sharepoint-2010-part-1-getting-started\/","title":{"rendered":"Using Data Services over SharePoint 2010 \u2013 Part 1 \u2013 Getting Started"},"content":{"rendered":"<p><P><A href=\"http:\/\/blogs.msdn.com\/adonet\/archive\/2009\/09\/01\/ado-net-data-services-v1-5-ctp2-now-available.aspx\">ADO.NET Data Services 1.5<\/A> and <A href=\"http:\/\/sharepoint.microsoft.com\/\">SharePoint 2010<\/A> allow developers to write applications against SharePoint Lists using the familiar Data Services Client programming model. <\/P>\n<H3>Setup<\/H3>\n<P>The SharePoint 2010 beta will become generally available in <A href=\"http:\/\/www.microsoft.com\/presspass\/press\/2009\/oct09\/10-19MSSharePointConf09PR.mspx\">November<\/A>. <\/P>\n<P>In order to use Data Services with SharePoint 2010 Beta, ADO.NET Data Services 1.5 must be installed on your server, ideally *before* you install SharePoint 2010. <BR><BR>If however SharePoint 2010 is already on your box when you install Data Services, you will need an <A href=\"http:\/\/www.bing.com\/search?q=iisreset&amp;go=&amp;form=QBLH&amp;qs=n\">iisreset<\/A> to make the Data Service Endpoint show-up.<BR><\/P>\n<P>And then to program against a Data Services enabled SharePoint box you need either:<\/P>\n<UL>\n<LI>VS 2008 SP1 with the ADO.NET Data Services 1.5 installed (<A href=\"http:\/\/blogs.msdn.com\/adonet\/archive\/2009\/09\/01\/ado-net-data-services-v1-5-ctp2-now-available.aspx\">CTP 2<\/A> only &#8211; the <A href=\"http:\/\/blogs.msdn.com\/astoriateam\/archive\/2010\/02\/15\/compatibility-note-sharepoint-2010-beta-data-services-update.aspx\">RTM is incompatible with the SharePoint 2010 Beta<\/A>) <BR><BR>or <BR><\/LI>\n<LI>VS 2010 (<A href=\"http:\/\/blogs.msdn.com\/somasegar\/archive\/2009\/10\/19\/announcing-visual-studio-2010-and-net-fx-4-beta-2.aspx\">Beta 2<\/A> or higher) <\/LI><\/UL>\n<H3>Where is your Data Service Endpoint?<\/H3>\n<P>Assuming you\u2019ve got everything setup and working the first thing you need to know is where your Data Service endpoint is installed.<\/P>\n<P>If your SharePoint site is <B>http:\/\/mflasko-dev\/<\/B> (thanks Mike) then your Data Services endpoint will be <B>http:\/\/mflasko-dev\/_vti_bin\/listdata.svc<\/B>.<\/P>\n<P>If you open one of these endpoints up in Internet Explorer you\u2019ll see something like this:<\/P>\n<P><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/DataServiceRoot.jpg\"><IMG title=\"DataServiceRoot\" border=\"0\" alt=\"DataServiceRoot\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/DataServiceRoot_thumb.jpg\" width=\"226\" height=\"244\"><\/A> <\/P>\n<P>As you can see this is a standard Data Services Atom feed, listing all the Lists on the SharePoint site.<\/P>\n<P>Cool.<\/P>\n<P>Once you know where your Data Service is located, the next step is to write your Data Services Client application.<\/P>\n<H3>Create the Sharepoint Application:<\/H3>\n<P>But first to demonstrate how easy this is, I\u2019ve used SharePoint to create the simplest of all Suggestion Tracking applications. <\/P>\n<P>You can follow along by following these simple steps:<\/P>\n<OL>\n<LI>Create a \u2018Suggestions\u2019 list which is based on an \u2018Issues\u2019 list. <\/LI>\n<LI>Finished! <\/LI><\/OL>\n<P>The resulting list looks something like this:<\/P>\n<P><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/Suggestions.jpg\"><IMG title=\"Suggestions\" border=\"0\" alt=\"Suggestions\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/Suggestions_thumb.jpg\" width=\"244\" height=\"35\"><\/A>&nbsp;<\/P>\n<P>The idea is that this list will capture all the suggestions users have for making a departmental line of business (LOB) application better. <\/P>\n<P>But rather than making people go to the SharePoint site to make the suggestion, we want to allow the users to do it right in the LOB application.<\/P>\n<H3>Talking to Sharepoint using Data Services:<\/H3>\n<P>The first step as always to add a service reference, using the location of the Data Service that exposes SharePoint data (i.e. <B>http:\/\/mflasko-dev\/_vti_bin\/listdata.svc<\/B>)<\/P>\n<P><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/AddServiceReference.jpg\"><IMG title=\"AddServiceReference\" border=\"0\" alt=\"AddServiceReference\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/AddServiceReference_thumb.jpg\" width=\"244\" height=\"198\"><\/A> <\/P>\n<P>Once you\u2019ve done this you will have CLR classes representing the types in each list, and you will have a strongly typed DataServiceContext called TeamSiteDataContext that allows you to access the data:<\/P>\n<P><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/ObjectBrowser.jpg\"><IMG title=\"ObjectBrowser\" border=\"0\" alt=\"ObjectBrowser\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/ObjectBrowser_thumb.jpg\" width=\"158\" height=\"244\"><\/A> <\/P>\n<P>Rather than focusing on how the user enters the suggest in your LOB application, lets focus on how to POST that suggestion to Sharepoint. <\/P>\n<P>To do that you need to write a method something like this:<\/P>\n<P><FONT face=\"Courier New\">public void PostSuggestion(string title, string description) <BR>{ <BR>&nbsp;&nbsp; TeamSiteDataContext ctx = new TeamSiteDataContext( <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new Uri( <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/FONT><FONT face=\"Courier New\">http:\/\/mflasko-dev\/_vti_bin\/listdata.svc<\/FONT><FONT face=\"Courier New\">,&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UriKind.Absolute <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ) <BR>&nbsp;&nbsp; ); <BR>&nbsp;&nbsp; ctx.AddToSuggestions( <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new SuggestionsItem{ <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Title = title,&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Description = description <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <BR>&nbsp;&nbsp; ); <BR>&nbsp;&nbsp; ctx.SaveChanges(); <BR>}<\/FONT><\/P>\n<P>As you can see this is very easy.<\/P>\n<P>In an environment like Silverlight it is a little more complicated because whenever you cross a network boundary have to deal with the Async and Threading issues. Which means you can\u2019t use SaveChanges() directly.<\/P>\n<P>You have to use the standard BeginXXX() and EndXXX() async pattern and you need to use the Dispatcher to ensure the results are marshaled back on the UI thread:<\/P><FONT face=\"Courier New\">\n<P>ctx.BeginSaveChanges( <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (IAsyncResult result) =&gt; Dispatcher.BeginInvoke( <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; () =&gt; ctx.EndSaveChanges(result)), <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctx <BR>&nbsp;&nbsp; );<\/P><\/FONT>\n<P>In future blog posts we will dig into this in more detail, covering topic like Query \/ Update \/ Data Binding, Blob Handling and security policies over Sharepoint.<\/P>\n<P>As always we are keen to hear your comments.<\/P>\n<P><B><A href=\"http:\/\/blogs.msdn.com\/alexj\">Alex James<\/A> <BR><\/B>Program Manager <BR>Microsoft<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>ADO.NET Data Services 1.5 and SharePoint 2010 allow developers to write applications against SharePoint Lists using the familiar Data Services Client programming model. Setup The SharePoint 2010 beta will become generally available in November. In order to use Data Services with SharePoint 2010 Beta, ADO.NET Data Services 1.5 must be installed on your server, ideally [&hellip;]<\/p>\n","protected":false},"author":512,"featured_media":3253,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[6,37,66,67,85],"class_list":["post-1603","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-odata","tag-ado-net-data-services","tag-how-to","tag-sharepoint","tag-silverlight","tag-whats-new"],"acf":[],"blog_post_summary":"<p>ADO.NET Data Services 1.5 and SharePoint 2010 allow developers to write applications against SharePoint Lists using the familiar Data Services Client programming model. Setup The SharePoint 2010 beta will become generally available in November. In order to use Data Services with SharePoint 2010 Beta, ADO.NET Data Services 1.5 must be installed on your server, ideally [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/posts\/1603","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/users\/512"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/comments?post=1603"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/posts\/1603\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/media\/3253"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/media?parent=1603"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/categories?post=1603"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/tags?post=1603"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}