• Topic
  • Discussion
  • VOS.VirtSPASQLSilverLightApp(Last) -- DAVWikiAdmin? , 2017-06-29 07:40:20 Edit WebDAV System Administrator 2017-06-29 03:40:20

    Creating a Silverlight Application to consume the service

    Introduction

    This document will guide you through creating an application for Silverlight that will consume the ADO.NET Data Service created in Creating a Web Browser Application to Access RDF Data using the Virtuoso ADO.NET Provider.

    Prerequisites

    1. The Microsoft Silverlight 2 Tools for Visual Studio 2008 SP1
    2. The ADO.NET Data Service created in Creating a Web Browser Application to Access RDF Data Using The Virtuoso ADO.NET Provider
    3. The Visual Studio project used to create the ADO.NET Data Service

    Creating the Application for Silverlight

    1. Open the ADO.NET Data Service project in Visual Studio.
    2. In the Solution Explorer right click on the RDFWebDemo solution and add a new Project.
    3. In the Add New Project dialog select Silverlight Application and click OK. This will open the Add Silverlight Application dialog.



    4. Select Link this Silverlight Control into an existing Web Site and make sure the Web Site selected is RDFWebDemo. Select Add a test page that references the application and Make it the start page.



    5. In Solution Explorer, select RDFWebDemo, open the Project menu and select Properties.
    6. Select the Web tab, and select Specific Page in the Start Action section. Click on the ellipsis ("?") and select SilverlightApplication1TestPage.html as the start page.
    7. Add a reference to the data service. In the Solution Explorer right click on SilverlightApplication1 and select Add Service Reference.
    8. In the Add Service Reference dialog click the Discover button. Your ADO.NET Data Service should appear in the Address box and the Services box.
    9. Select the service and click OK. ServiceReference1 will now be added to the ServiceReferences.
    10. Open page.xaml.cs and add references to the service and to the System.Data.Services.Client assembly by adding the following using statements at the top of the file:

      using System.Data.Services.Client; using SilverlightApplication1.ServiceReference1;

    11. We need to create a data service context to reference the data from the service and to load data from the view, sparqlview, exposed by the service. Add the following lines to the page constructor after InitializeComponent()

      DataServiceContext svcCtx = new DataServiceContext(new Uri("WebDataService1.svc", UriKind.Relative)); svcCtx.BeginExecute<sparqlview>(new Uri("sparqlview", UriKind.Relative), loadSCallback, svcCtx);

    12. Add the loadSCallback method to the page class. The method loads the data from sparqlview and puts it in a List. This List populates a list box on the page.

      private void loadSCallback(IAsyncResult asyncResult) { List<Uri> uList = new List<Uri>(); DataServiceContext ctx = asyncResult.AsyncState as DataServiceContext; foreach (sparqlview sv in ctx.EndExecute<sparqlview>(asyncResult)) uList.Add(new Uri(sv.s)); listBox1.DataContext = uList; }

    13. Add the list box to the page. In the Solution Explorer double click on page.xaml to open it in the editor. Add the following code between the <grid> and </grid> tags.

      <ListBox x:Name="listBox1" HorizontalAlignment="Stretch" Margin="25,8,26,-78" Grid.RowSpan="1" Grid.Row="0" VerticalAlignment="Stretch" ItemsSource="{Binding Mode=OneWay}" > <ListBox.ItemTemplate> <DataTemplate> <StackPanel x:Name="DisplayListData" Orientation="Horizontal" VerticalAlignment="Bottom" Margin="5" > <HyperlinkButton Content ="{Binding}" NavigateUri="{Binding}" Margin="5,0,0,0" VerticalAlignment="Bottom" HorizontalAlignment="Left" FontSize="12"> </HyperlinkButton> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox>

    14. Build the Silverlight application and launch without debugging using Ctrl-F5. This will launch the browser and open SilverlightApplication1TestPage.aspx.



      Clicking on one of the IRIs will open the page using description.vsp.



    Related