|
-
Aug 28th, 2013, 09:48 AM
#1
Thread Starter
Fanatic Member
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)?
-
Aug 29th, 2013, 05:44 AM
#2
Thread Starter
Fanatic Member
Re: What's the best way to return data from a WCF data service?
I'm starting to consider changing my name to Tumbleweed.
-
Aug 29th, 2013, 06:33 AM
#3
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
-
Aug 29th, 2013, 08:34 AM
#4
Thread Starter
Fanatic Member
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.
-
Sep 3rd, 2013, 10:31 AM
#5
Thread Starter
Fanatic Member
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?
-
Sep 3rd, 2013, 02:44 PM
#6
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
-
Sep 3rd, 2013, 02:48 PM
#7
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.
-
Sep 6th, 2013, 04:41 AM
#8
Thread Starter
Fanatic Member
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...
-
Sep 6th, 2013, 08:00 AM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|