ASP.NET
  Home arrow ASP.NET arrow Page 2 - Developing Your First Silverlight Applicat...
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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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? 
ASP.NET

Developing Your First Silverlight Application Using Visual Studio 2008
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 9
    2007-11-07

    Table of Contents:
  • Developing Your First Silverlight Application Using Visual Studio 2008
  • Creating an ASP.NET 3.5 Web Service using Visual Studio 2008 beta: source code
  • Adding a Silverlight Project to the Visual Studio 2008 solution
  • Adding a Silverlight Project to Visual Studio 2008 solution: hosting in IIS
  • Consuming the ASP.NET Web Service from the Silverlight application using the Visual Studio 2008 solution

  • 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


    Developing Your First Silverlight Application Using Visual Studio 2008 - Creating an ASP.NET 3.5 Web Service using Visual Studio 2008 beta: source code


    (Page 2 of 5 )


    Once the project is created (as shown in the previous section), modify “ProductService.vb” to match the following:


    Imports System.Web.Services

    Imports System.Web.Services.Protocols

    Imports System.ComponentModel

    Imports System.Data.SqlClient


    ' To allow this Web Service to be called from script, using ASP.NET AJAX,
    uncomment the following line.

    <System.Web.Script.Services.ScriptService()> _

    <System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _

    <System.Web.Services.WebServiceBinding
    (ConformsTo:=WsiProfiles.BasicProfile1_1)> _

    <ToolboxItem(False)> _

    Public Class ProductService

    Inherits System.Web.Services.WebService

    <WebMethod()> _

    Public Function GetProductInfo(ByVal ProductID As Integer) As Product

    Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings
    ("cnNorthwind").ConnectionString)

    Using cmd As New SqlCommand("SELECT ProductID, ProductName, UnitPrice,
    UnitsInStock, UnitsOnOrder,(SELECT sum(UnitPrice * Quantity) FROM dbo.
    [Order Details] WHERE ProductID = a.ProductID) as SaleValue FROM
    dbo.Products as a WHERE ProductID="
    & ProductID, cn)

    cmd.Connection.Open()

    Using rdr As SqlDataReader = cmd.ExecuteReader

    If rdr.Read() Then

    Return New Product With {.ProductID = rdr(rdr.GetOrdinal("ProductID")),
    .ProductName = rdr(rdr.GetOrdinal("ProductName")) & "", .UnitPrice = rdr
    (rdr.GetOrdinal("UnitPrice")) & "", .UnitsInStock = rdr(rdr.GetOrdinal
    ("UnitsInStock")) & "", .UnitsOnOrder = rdr(rdr.GetOrdinal
    ("UnitsOnOrder")) & "", .SaleTillToDate = rdr(rdr.GetOrdinal("SaleValue"))
    & ""}

    Else

    Return Nothing

    End If

    End Using

    cmd.Connection.Close()

    End Using

    End Using

    End Function

    End Class


    Make sure that the following attribute is added to the class (otherwise the “Error invoking Service” may be raised):


    <System.Web.Script.Services.ScriptService()>


    Modify “Web.Config” to include the following:


    <connectionStrings>

    <add name="cnNorthwind" connectionString="Data Source=.sql2k5;initial
    catalog=Northwind;user id=sa;password=eXpress2005"/>

    </connectionStrings>


    Add a new class named “Product.vb” to the web service project (right click on project and select “Add new Item”). Modify it to match the following:


    Public Class Product


    Private _ProductID As Integer

    Private _ProductName As String

    Private _UnitPrice As Double

    Private _UnitsInStock As Integer

    Private _UnitsOnOrder As Integer

    Private _SaleTillToDate As Integer


    Public Property ProductID() As Integer

    Get

    Return _ProductID

    End Get

    Set(ByVal value As Integer)

    _ProductID = value

    End Set

    End Property


    Public Property ProductName() As String

    Get

    Return _ProductName

    End Get

    Set(ByVal value As String)

    _ProductName = value

    End Set

    End Property


    Public Property UnitPrice() As Double

    Get

    Return _UnitPrice

    End Get

    Set(ByVal value As Double)

    _UnitPrice = value

    End Set

    End Property


    Public Property UnitsInStock() As Integer

    Get

    Return _UnitsInStock

    End Get

    Set(ByVal value As Integer)

    _UnitsInStock = value

    End Set

    End Property


    Public Property UnitsOnOrder() As Integer

    Get

    Return _UnitsOnOrder

    End Get

    Set(ByVal value As Integer)

    _UnitsOnOrder = value

    End Set

    End Property


    Public Property SaleTillToDate() As Integer

    Get

    Return _SaleTillToDate

    End Get

    Set(ByVal value As Integer)

    _SaleTillToDate = value

    End Set

    End Property


    End Class

    More ASP.NET Articles
    More By Jagadish Chaterjee


       · Hello guys,This is my first contribution on Silverlight technologies. This...
       · Hi Jag,I've been searching for days for something like you've written here. This...
     

    ASP.NET ARTICLES

    - Disadvantages of the ASP.NET MVC Framework
    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX
    - Building a Simple Storefront with LINQ





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT