Click here to Skip to main content
15,895,538 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I'm new to WCF and need to create an IIS hosted WCF Service that will run a stored procedure that accepts a record ID and returns a single record that has 25 fields. What is the easiest way to accomplish this given the number of fields being returned from the stored procedure. WCF information with the least bit of complexity is frustratingly difficult to find. :( Would like to move from web service to WCF...
PS - Using VS2012 and VB but can convert C# to VB if necessary.

Upon further research while waiting for an answer, it appears I can use the dataset from the sql and then need to convert it to xml to return the value from the service?

[EDIT]

SQL
ALTER PROCEDURE [dbo].[procImpoundRec_Get]
    @ID intASBEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT *
FROM tblImpoundRecs
WHERE ID = @ID

END


Here's the Interface in AADM_Service_Interface:
VB
<servicecontract()>
Public Interface AADM_Service_Interface
<operationcontract()>
Function Impound_Get(ByVal ID As Integer) As String
End Interface


Here's the implementation:
VB
Public Class AADM_Service
    Implements AADM_Service_Interface

Public Function Impound_GetRecord(ID As Integer) As String Implements AADM_Service_Interface.Impound_Get
Dim objConnect As New SqlConnection(ConnectionStrings.AADM)
Dim myCommand As SqlCommand = New SqlCommand
Dim strReturnRecord As String = ""
With myCommand .Connection = objConnect .CommandText = "procImpoundRec_Get"
    .CommandType = CommandType.StoredProcedure .Parameters.Add(New SqlParameter("@ID", ID))
End With

Dim objDataAdapter As New SqlDataAdapter(myCommand)
Dim ds As New DataSet

Try
    objDataAdapter.Fill(ds)
    strReturnRecord = ds.GetXml

Catch ex As Exception

End Try

Return strReturnRecord

End Function

End Class


Moved from comment[/EDIT]
Posted
Updated 19-Nov-12 8:42am
v4
Comments
Maciej Los 16-Nov-12 16:49pm    
What have you done till now?
Scoobydoozie 19-Nov-12 8:53am    
Created all SQL components. Here's the stored procedure:

ALTER PROCEDURE [dbo].[procImpoundRec_Get] @ID intASBEGIN

-- SET NOCOUNT ON added to prevent extra result sets from

-- interfering with SELECT statements. SET NOCOUNT ON; SELECT * FROM

tblImpoundRecs WHERE ID = @IDEND


Here's the Interface in AADM_Service_Interface:

<servicecontract()>
Public Interface AADM_Service_Interface

<operationcontract()>
Function Impound_Get(ByVal ID As Integer) As String

End Interface

Here's the implementation:

Public Class AADM_Service
Implements AADM_Service_Interface

Public Function Impound_GetRecord(ID As Integer) As String Implements AADM_Service_Interface.Impound_Get
Dim objConnect As New SqlConnection(ConnectionStrings.AADM)
Dim myCommand As SqlCommand = New SqlCommand
Dim strReturnRecord As String = ""

With myCommand
.Connection = objConnect
.CommandText = "procImpoundRec_Get"
.CommandType = CommandType.StoredProcedure
.Parameters.Add(New SqlParameter("@ID", ID))
End With

Dim objDataAdapter As New SqlDataAdapter(myCommand)
Dim ds As New DataSet

Try
objDataAdapter.Fill(ds)
strReturnRecord = ds.GetXml
Catch ex As Exception

End Try

Return strReturnRecord

End Function

End Class
RDBurmon 11-Jan-13 3:59am    
Sorry I have to copy this reply to answer . Easy for OP to read

1 solution

Created all SQL components. Here's the stored procedure:

SQL
ALTER PROCEDURE [dbo].[procImpoundRec_Get] 
@ID intASBEGIN 

-- SET NOCOUNT ON added to prevent extra result sets from 
-- interfering with SELECT statements. 

SET NOCOUNT ON; 

SELECT * FROM tblImpoundRecs WHERE ID = @IDEND 


Here's the Interface in AADM_Service_Interface:

VB.NET
<servicecontract()> 
Public Interface AADM_Service_Interface <operationcontract()> 
  Function Impound_Get(ByVal ID As Integer) As String 
End Interface 

Here's the implementation:
VB.NET
Public Class AADM_Service Implements AADM_Service_Interface 
 Public Function Impound_GetRecord(ID As Integer) As String 
 Implements AADM_Service_Interface.Impound_Get 
 Dim objConnect As New SqlConnection(ConnectionStrings.AADM) 
 Dim myCommand As SqlCommand = New SqlCommand 
 Dim strReturnRecord As String = "" 
 With myCommand 
  .Connection = objConnect 
  .CommandText = "procImpoundRec_Get" 
  .CommandType = CommandType.StoredProcedure 
  .Parameters.Add(New SqlParameter("@ID", ID)) 
 End With 
 Dim objDataAdapter As New SqlDataAdapter(myCommand) 
 Dim ds As New DataSet 
 Try objDataAdapter.Fill(ds) 
 strReturnRecord = ds.GetXml 
 Catch ex As Exception 
 End Try 

Return strReturnRecord 
End Function 
End Class
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900