Windows Scripting
  Home arrow Windows Scripting arrow Page 4 - Creating a Silverlight 2.0 Application tha...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Creating a Silverlight 2.0 Application that Consumes a WCF Service
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2008-11-05

    Table of Contents:
  • Creating a Silverlight 2.0 Application that Consumes a WCF Service
  • Configuring for Silverlight
  • Writing Code
  • Adding a Project

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Creating a Silverlight 2.0 Application that Consumes a WCF Service - Adding a Project


    (Page 4 of 4 )

    Now we need to develop a Silverlight 2 application which consumes our regular WCF Service.

    The following are the necessary steps to get started:

    • Open Visual Studio 2008.

    • Go to File || Add || New Project (to the existing solution).

    • Select “Silverlight” as the "Project Type," “Silverlight Application” as the "Template," “DemoSL” as the "Name" and finally click “OK.”

    • You will be provided with an “Add Silverlight Application” dialog.

    • Select “Add a new Web to the solution” (first radio button).

    • Select “Web Application Project” as the "Project Type," “DemoSLWeb” as the "Name" and finally click on “OK” (as shown in Fig 09).


    If you observe the “Solution explorer” now, you will find two projects. One is the Silverlight application itself and the other is simply a web application which is used to render and test the Silverlight application developed.

    Now that we've created a new Silverlight application, we need to add a reference to the WCF Service we developed earlier. 

    Using “Solution Explorer," right click on the “DemoSL” project and “Add Service Reference” to “DemoEmpService” as shown below (Fig 10). Rebuild the solution.


    Modify the “ServiceReferences.ClientConfig” in “DemoSL” as follows (Fig 11). Rebuild the solution.



    Developing a Silverlight 2 application to consume WCF: Writing code

    Drag and drop a button, label and a Datagrid from the toolbox onto the Silverlight design surface. Modify your code so that it looks like the following:


    <UserControl xmlns:my="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" x:Class="DemoSL.Page"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Width="400" Height="300">

     <Grid x:Name="LayoutRoot" Background="White">

     <Grid.RowDefinitions>

     <RowDefinition Height="0.15*"/>

     <RowDefinition Height="0.25*"/>

     <RowDefinition Height="0.60*"/>

     </Grid.RowDefinitions>

     <Button HorizontalAlignment="Left" Margin="5,5,0,0" VerticalAlignment="Stretch" Width="76" Content="Show" x:Name="btnShow" Height="30" />

     <TextBlock Margin="5,5,0,0" VerticalAlignment="Stretch" Text="" TextWrapping="Wrap" x:Name="lblMsg" Height="22" Grid.Row="1" />

     <my:DataGrid x:Name="dgEmployees" AutoGenerateColumns="True" Grid.Row="2"></my:DataGrid>

     </Grid>

    </UserControl>


    Once the datagrid control is added to the Silverlight application, you should have a “System.Windows.Controls.Data” assembly added to your reference list. You should also observe the namespace “my” added to the “UserControl” tag.

    Go to the code-behind of the “Page.xaml” and modify the code to look like the following:


    Partial Public Class Page

    Inherits UserControl


    Public Sub New()

    InitializeComponent()

    End Sub


    Private Sub EmployeeListFetched(ByVal sender As Object, ByVal e As EmpService.GetEmployeeListCompletedEventArgs)

    Me.dgEmployees.ItemsSource = e.Result

    Me.lblMsg.Text = "Fetched!"

    End Sub


    Private Sub btnShow_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnShow.Click

    Me.lblMsg.Text = "Fetching..."

    Dim objService As New EmpService.EmpServiceClient

    AddHandler objService.GetEmployeeListCompleted, AddressOf EmployeeListFetched

    objService.GetEmployeeListAsync()

    End Sub


    End Class


    Once you execute your Silverlight application, you should see the output as follows:


    Fig 12


    In my upcoming articles, we will see more and more examples of Silverlight 2.0 development. I hope you enjoyed the article and any suggestions, bugs, errors, enhancements etc. are highly appreciated at http://jagchat.spaces.live.com


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Hello guys,This is my second article in series focusing on "Siverlight 2.0...
       · This is the most thorough Silverlight data binding I found so far. However I hot...
     

    WINDOWS SCRIPTING ARTICLES

    - More Windows Scripting Workarounds from Nilpo
    - Overloading Methods and More in VBScript
    - Improving MFC for Windows Vista
    - Regular Expressions in VBScript
    - Working with Dates in WMI
    - Completing Calendars with VBScript Date Func...
    - Building Calendars with VBScript Date Functi...
    - Working With Dates and Times in VBScript
    - Designing WCF DataContract Classes Using the...
    - Understanding Dates and Times in VBScript
    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek