silverlight应用程序 - 找不到服务器错误

时间:2011-04-15 21:33:42

标签: vb.net silverlight sql-server-2008

我正在按照教程创建一个Silverlight Web应用程序,该应用程序使用数据网格并从表中获取数据,但是我一直只使用NotFound获取服务器错误而没有进一步的细节。不确定如何跟踪错误。

Imports System.ServiceModel
Imports System.ServiceModel.Activation

   

Public Class Service2

<OperationContract()>
Public Function DoWork() As List(Of RealTimeCount)
    Try
        Dim df As New DataClasses2DataContext
        Dim counts = (From record In df.RealTimePostCounts Order By record.pollDate, record.boxFeed, record.boxCount Select record)
        Dim list As New List(Of RealTimeCount)
        For Each d In counts
            list.Add(New RealTimeCount With {.getDate = d.pollDate, .boxItem = d.boxFeed, .boxSum = d.boxCount})
        Next

        Return list

    Catch ex As Exception....

 end try
 end function 
end class



Public Class MainPage
Inherits UserControl

Private WithEvents mservice As New ServiceReference1.Service2Client()


Public Sub New()
    InitializeComponent()
End Sub


Private Sub btnLoad_Click
  (ByVal sender As System.Object,
       ByVal e As System.Windows.RoutedEventArgs) Handles btnLoad.Click
    mservice.DoWorkAsync()

End Sub

Private Sub mservice_DoWorkCompleted
  (ByVal sender As Object, 
  ByVal e As ServiceReference1.DoWorkCompletedEventArgs) 
   Handles mservice.DoWorkCompleted
    DataGrid1.ItemsSource = e.Result
    DataGrid1.Visibility = Windows.Visibility.Visible
End Sub
 End Class

2 个答案:

答案 0 :(得分:1)

这个错误极具误导性和令人沮丧。当我遇到它时,我运行fiddler2(http://www.fiddler2.com),它捕获网络流量并将告诉你失败的确切原因。我见过的最常见的问题是合同不匹配和客户端访问策略错误。

答案 1 :(得分:1)

您似乎没有为Silverlight应用程序添加服务 您可以使用WCF或WCF RIA服务 使用RIA服务的Here is教程。它使用DataGrid控件,代码可用于VB和C# Silverlight 3: Displaying SQL Server Data是使用WCF服务在DataGrid控件上显示数据的其他示例。

希望这会对你有所帮助。