views:

279

answers:

1

Hi, guys. I'm pretty new to both Silverlight and WCF. What I'm trying to do is provide a database connection to my Silverlight object. The problem I'm having, though, is that my web service, while it compiles fine, doesn't seem to be returning anything at all. I've used Fiddler, and tried a custom request, but the service itself isn't returning anything at all.

My service code:

Imports System.ServiceModel
Imports System.ServiceModel.Activation
Imports System.Data.OleDb
Imports System.Runtime.Serialization

<ServiceContract(Namespace:="")> _ 
<AspNetCompatibilityRequirements(RequirementsMode := AspNetCompatibilityRequirementsMode.Allowed)> _ 
Public Class DBConnection

    Dim dbConn As OleDbConnection

    Private Function OpenConnection(ByVal strConnection As String) As Boolean
        Try
            Dim blnConnected As Boolean = False
            dbConn = New OleDbConnection(strConnection)
            dbConn.Open()
        Catch ex As OleDbException
            Return False
        End Try
        Return True
    End Function

    Private Function CloseConnection() As Boolean
        Try
            dbConn.Close()
            dbConn = Nothing
        Catch ex As OleDbException
            Return False
        End Try
        Return True
    End Function

    <OperationContract()> _
    Public Function GetDataTable(ByVal strSQL As String, ByVal strConnection As String) As DataTable
        If dbConn Is Nothing Then OpenConnection(strConnection)

        Dim dtTable As New DataTable
        Dim dbAdapter As New OleDbDataAdapter(strSQL, dbConn)

        dbAdapter.Fill(dtTable)

        CloseConnection()

        Return dtTable
    End Function
End Class

When I breakpoint it on the last line of GetDataTable, there ARE results there. And I know it's hitting the service because of that, too.

So obviously, I'm doing something wrong, but I have absolutely no idea what.

A: 

You must be getting something in Fiddler if you see

“The remote server returned an error: NotFound” error.

Is there an HTTP error code at least?

----- Updated

Use DataSet instead of DataTable as the return type. Put the table inside of the DataSet before returning and grab the first Table.

Paully
That's the wierd part; Fiddler returns an error code of 0. From what I can tell, the WCF session is getting terminated as soon as the object is returned, but there's absolutely no response data. Also, I'm getting the NotFound error in my code when it hits the pre-generated EndInvoke code. It's like the function it's trying to invoke doesn't exist or something.
Frank Bueckert
I'm wondering if you WCF can handle the size, you may need to increase the size of the buffer. Can you try putting the table in a dataset and return that to see if it works?
Paully
Surprise, surprise. Changing it to a DataSet makes it return something. That's awesome. So how would I go about fixing it, then?
Frank Bueckert
Oh great, then just replace the return type with DataSet and in the DataSet's Table property..attach your table (i.e ds.Tables.Add(mytable). From the client side, just open the first table in the dataset, i.e dim dt as datatable = datasets.Table(0).
Paully
Perfect! That'll allow me to massage the response to do what I need it to do. Thanks!
Frank Bueckert
Yay!! Keep chugging!
Paully