Results 1 to 9 of 9

Thread: What's the best way to return data from a WCF data service?

  1. #1

    Thread Starter
    Fanatic Member InvisibleDuncan's Avatar
    Join Date
    May 2001
    Location
    Eating jam.
    Posts
    819

    What's the best way to return data from a WCF data service?

    I'm planning to use a VB.Net WCF data service as the way for various applications to retrieve data from a selection of back end databases. I don't want to have to fill my service with classes that represent the data entities, and I've seen suggestions that returning data tables from a data service is a bad idea (although I've seen no clear explanation as to why). So, does anyone have any suggestions as to what is the best way to return the data?

    In conjunction with that, I would like to be able to able to throw any request at this service without it having to be predefined in the service's model. For example, I would like to be able to create a new stored procedure in my database and have a new function in my client to call that SP via the service, but not have to recompile the service to be able to recognise it - the client would simply pass in the stored procedure name and a collection of parameters and have the service return the data to the client in some form. Anyone have any ideas whether this is feasible (or indeed desirable)?
    Indecisiveness is the key to flexibility.

    www.mangojacks.com

  2. #2

    Thread Starter
    Fanatic Member InvisibleDuncan's Avatar
    Join Date
    May 2001
    Location
    Eating jam.
    Posts
    819

    Re: What's the best way to return data from a WCF data service?

    I'm starting to consider changing my name to Tumbleweed.
    Indecisiveness is the key to flexibility.

    www.mangojacks.com

  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: What's the best way to return data from a WCF data service?

    Ok - I've got this in a web method that I call from an ajax request in a browser - does this help you at all? I don't do WCF - but it cannot be all that different.

    Code:
        <WebMethod()> _
        <ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=False)> _
        Public Function CtrlService(ByVal ctrloption As String, ByVal ctrlval1 As String _
                                                                                    , ByVal ctrlval2 As String _
                                                                                    , ByVal ctrlval3 As String _
                                                                                    , ByVal username As String _
                                                                                    , ByVal source As IList(Of Dictionary(Of String, String))) As String
            Dim credDB As String = ""
            If username.Contains(":") Then
                credDB = username.Split(":"c)(0)
                username = username.Split(":"c)(1)
            End If
    
            Dim JsonMaker As JsonWriter = New JsonWriter
    
            With JsonMaker
                .StartObject()
    
                Dim strMessage As String = "%no operation performed%"
                Dim strSuccess As String = "success"
    
                If ctrloption = "excel" Then
                    .NewObject("excel", "true")
                    .Seperate()
    
    .
    .
    .
                If ctrloption = "login" Then
                    Dim nGuid As Guid = Guid.NewGuid
                    Dim didClear As Boolean = False
                    Dim errText As String = ""
                    .NewObject("login", "true")
                    .Seperate()
    .
    .
    .
                .NewObject("success", strSuccess)
                .Seperate()
                .NewObject("message", strMessage)
                .EndObject()
            End With
    
            Return JsonMaker.GetJson()
        End Function

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  4. #4

    Thread Starter
    Fanatic Member InvisibleDuncan's Avatar
    Join Date
    May 2001
    Location
    Eating jam.
    Posts
    819

    Re: What's the best way to return data from a WCF data service?

    Thanks - I'll have a poke around that and see what's going on.
    Indecisiveness is the key to flexibility.

    www.mangojacks.com

  5. #5

    Thread Starter
    Fanatic Member InvisibleDuncan's Avatar
    Join Date
    May 2001
    Location
    Eating jam.
    Posts
    819

    Re: What's the best way to return data from a WCF data service?

    That has helped a bit, but does anyone have any opinions on the best way to return data? Am I okay to use a DataTable, or would I be better with XML, or is there a completely different data type that I should use?
    Indecisiveness is the key to flexibility.

    www.mangojacks.com

  6. #6
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: What's the best way to return data from a WCF data service?

    In regards to a type to return, I favor (thinking my service is being used by a web application) JSON. Nothing to show for code as my services are broken down into small segments i.e. a Interface project only, another project with classes, another project to get data etc.

    Solution layout
    Name:  S1.jpg
Views: 446
Size:  55.9 KB

  7. #7
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: What's the best way to return data from a WCF data service?

    I agree with the JSON format - it's becoming a standard from what I see. It's native-language to JavaScript and relates easily to common data types on the back end service side.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  8. #8

    Thread Starter
    Fanatic Member InvisibleDuncan's Avatar
    Join Date
    May 2001
    Location
    Eating jam.
    Posts
    819

    Re: What's the best way to return data from a WCF data service?

    I've never even heard of JSON, which is a little worrying. Time for some research, I reckon.

    Thanks, guys - I'm sure I'll be back with more questions fairly soon...
    Indecisiveness is the key to flexibility.

    www.mangojacks.com

  9. #9
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: What's the best way to return data from a WCF data service?


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width