Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# VB SQL WCF StoredProcedures , +
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. Frown | :( 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]
 
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:
<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
 
Moved from comment[/EDIT]
Posted 16-Nov-12 9:23am
Edited 19-Nov-12 8:42am
Maciej Los131.4K
v4
Comments
Maciej Los at 16-Nov-12 16:49pm
   
What have you done till now?
Member 8051489 at 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:
 

Public Interface AADM_Service_Interface
 

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
Rahul Dhoble at 11-Jan-13 3:59am
   
Sorry I have to copy this reply to answer . Easy for OP to read

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  

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



Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 11 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid