Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Publish Your Database as Silverlight in 15 Minutes

0.00/5 (No votes)
30 Mar 2009 1  
Guide to creating a very cool Silverlight application from any database schema in 15 minutes.

ZSilver18.gif

Introduction

The purpose of this article is to introduce you to a tool that will jump start your Silverlight development by converting any database schema you have into a Silverlight application. You can quickly check the live demo here: http://sphinx4.webhop.net/Silver, to see if this article is worth reading.

The tool is free, and available for download from http://www.z-software.com.

The tool will not only generate the code, but will also compile it so when you download your project it is ready to be used, and that’s where we will start our journey here.

The tool works by you submitting the database schema to the Z-Software server, and after a few minutes, you download a completed project which includes the SOAP service, the WCF service, and several clients. The download will also include the compiled binaries for the two services needed to connect the Silverlight application to the database server.

The tool you download from Z-Software includes a utility to generate the Silverlight code we are about to discuss here.

Using the code

  1. Unzip the contents into a folder. We will refer to this folder as ZProjectFolder from now on.
  2. Navigate to ZProjectFolder\Bin and double-click on WebAppMakerServiceConfig.exe.
  3. ZSilver01.gif

    Service Configurations Utility
  4. Enter the correct parameters, and click OK.
  5. Navigate to ZProjectFolder\dotNET\Service\<Your-Project>Site and double click ZProjectFolder.
  6. ZSilver02.gif

    WCF Service Site Configuration Utility
  7. Enter the site name and press OK.
  8. You should now have a web site called http://localhost/ZSampleService hosting the WCF service, and you can test it by typing http://localhost/ZSampleService/service.svc in a web browser.
  9. Start Visual Studio 2008 (SP1 is required).
  10. Select New Project from the File menu.
  11. ZSilver03.gif

    New Silverlight Project
  12. Enter the project name and press OK.
  13. ZSilver04.gif

    Project options
  14. Press OK to create the project skeleton.
  15. Right-click on the project node and select Add Service Reference...
  16. ZSilver05.gif

    Add Service Reference
  17. The following dialog will appear:
  18. ZSilver06.gif

    Add Service Reference dialog
  19. Type the URL that points to the WCF service and press Go.
  20. The service name should appear in the Services list box on the left.
  21. Type the name of the service reference, and press OK.
  22. Start the Z-Silverlight Gold utility, and select the database that was used to create the WCF service from the drop-down list.
  23. ZSilver07.gif

    Z-Silverlight Gold
  24. Select the desired layout, and "Click to configure".
  25. ZSilver08.gif

    Configure table columns
  26. Repeat the process for other tables needed for the layout.
  27. The Relations button will be enabled.
  28. ZSilver09.gif

    The Relations button enabled
  29. Click the Relations button and configure the (one to many) relations.
  30. ZSilver10.gif

    One to Many relations
  31. Press OK and then press the Parameters button.
  32. ZSilver11.gif

    Code options
  33. Make sure you enter the same namespace you have in your C# project and press OK.
  34. The XAML and C# tabs will appear.
  35. ZSilver12.gif

    Generated XAML and C# code
  36. Copy the XAML code and replace the entire Page.XAML code.
  37. Drag a Grid and GridSplitter from the Visual Studio Toolbox inside the first <Grid> tag.
  38. ZSilver13.gif

  39. Drag the Grid and GridSplitter to Add Namespace Reference to XAML Code.
  40. Make sure that the basics and data namespaces are added without messing up the XAML page.
  41. ZSilver14.gif

    XAML rendered OK
  42. Right-click on the project and select Add Class...

    ZSilver15.gif

    Add Class
  43. Enter class name and press OK.
  44. ZSilver16.gif

    New Class dialog
  45. Copy the generated C# from the Z-Silverlight Gold tool, and replace the entire class with the generated code.
  46. Add a call to zInit(); in the main Page.xaml.cs code.
  47. ZSilver17.gif

    Call zInit();
  48. Make sure you have the clientaccesspolicy.xml file in the root folder of your website. If you don't have one, download one from here: http://z-software.com/download/clientaccesspolicy.zip.
  49. Compile and run the project.
  50. The browser should display the following:

    ZSilver18_small.gif

    Published database

Points of interest

Make sure that when you drag the Grid or GridSplitter to the XAML code, the reference to the basics and data namespaces are added correctly.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here