This question is locked. New answers and comments are not allowed.
Hi,
I created a WCF web service to get data from sql database but im not sure how to call the web service from Silverlight.
I search for articles but no luck. I have to return the Top Sales Item from SQL database then generate a telerik chart. I declared an instance of WCF Service, but it doesnt go to the mService_GetTop10SalesItemsCompleted event. Kindly check the code below.
Web Service
Class
XAML
Thanks,
Cielo
I created a WCF web service to get data from sql database but im not sure how to call the web service from Silverlight.
I search for articles but no luck. I have to return the Top Sales Item from SQL database then generate a telerik chart. I declared an instance of WCF Service, but it doesnt go to the mService_GetTop10SalesItemsCompleted event. Kindly check the code below.
Web Service
| Imports System.ServiceModel |
| Imports System.ServiceModel.Activation |
| ' NOTE: If you change the class name "IEGSDashboardService" here, you must also update the reference to "IEGSDashboardService" in Web.config. |
| <ServiceContract()> _ |
| Public Interface IEGSDashboardService |
| <OperationContract()> _ |
| Function GetTop10SalesItems(ByVal intLocation As Integer, ByVal dteDay As Date) As List(Of TopSalesItem) |
| End Interface |
| ' NOTE: If you change the class name "EGSDashboardService" here, you must also update the reference to "EGSDashboardService" in Web.config and in the associated .svc file. |
| Public Class EGSDashboardService |
| Implements IEGSDashboardService |
| Public Function GetTop10SalesItems(ByVal intLocation As Integer, ByVal dteDay As Date) As System.Collections.Generic.List(Of TopSalesItem) Implements IEGSDashboardService.GetTop10SalesItems |
| If intLocation = 0 Then intLocation = -1 |
| Dim SalesItemList As New List(Of TopSalesItem) |
| Try |
| Dim ctx As New DashboardDataContext |
| Dim q = From c In ctx.DashboardGetTopSalesItems(intLocation, dteDay, dteDay.AddDays(30)) |
| For Each item In q |
| SalesItemList.Add(New TopSalesItem(item.Name, item.Amount)) |
| Next |
| Catch ex As Exception |
| SalesItemList = Nothing |
| End Try |
| Return SalesItemList |
| End Function |
Class
| Public Class TopSalesItem |
| Private _name As String |
| Private _amount As Double |
| Public Property Name() As String |
| Get |
| Return _name |
| End Get |
| Set(ByVal value As String) |
| _name = value |
| End Set |
| End Property |
| Public Property Amount() As Double |
| Get |
| Return _amount |
| End Get |
| Set(ByVal value As Double) |
| _amount = value |
| End Set |
| End Property |
| Public Sub New(ByVal name As String, ByVal amount As Double) |
| _name = name |
| _amount = amount |
| End Sub |
| Public Sub New() |
| End Sub |
| End Class |
XAML
| Imports Telerik.Windows.Controls.Charting |
| Imports System.Xml.Linq |
| Imports System.Windows.Interop |
| Imports System.Windows.Resources |
| Imports System.Reflection |
| Imports System.IO |
| Imports System.ComponentModel |
| Imports System.Linq |
| Imports System.Collections.ObjectModel |
| Imports System.Collections.Generic |
| Imports System.Net |
| Imports Telerik.Windows.Controls |
| Imports EGSDashboard_SL.DashboardService |
| Partial Public Class MainPage |
| Inherits UserControl |
| Public intLoc As Integer |
| Public strLoc As String |
| Public intDrillDown As Integer |
| 'Create a new instance of our WCF Service |
| Public WithEvents mService As New EGSDashboardServiceClient |
| Public Sub New() |
| InitializeComponent() |
| End Sub |
| Private Sub MainPage_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded |
| Dim mService As DashboardService.EGSDashboardServiceClient = New DashboardService.EGSDashboardServiceClient() |
| AddHandler mService.GetTop10SalesItemsCompleted, AddressOf mService_GetTop10SalesItemsCompleted |
| mService.GetTop10SalesItemsAsync(-1, "03/23/2010") |
| End Sub |
| Private Sub mService_GetTop10SalesItemsCompleted(ByVal sender As Object, ByVal e As DashboardService.GetTop10SalesItemsCompletedEventArgs) Handles mService.GetTop10SalesItemsCompleted |
| Dim x As Object |
| x = e.Result |
| End Sub |
Thanks,
Cielo