Results 1 to 2 of 2

Thread: [2005] Expose Collections class via web service

  1. #1

    Thread Starter
    Addicted Member Tjoppie's Avatar
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    241

    [2005] Expose Collections class via web service

    Hi There,

    I want to create a collections class where I can populate a class with items in a SQL DB and then iterate through them via my code...

    This is the scenario:

    I have got a table which keeps application settings. Now I want to expose these settings per application via a web service.... so in my webservice I want to expose an object which is called "AppSettings"

    so then in my application I want to call it in some kind of way like the following:


    Code:
    For Each Item as string in WebService.Appsettings.items(ApplicationID_Integer) 
    
    Dim SettingID as string = item.ID 
    Dim SettingName as string = item.Name 
    Dim SettingValue as string = item.Value 
    
    Loop

    I hope what I want is clear... so I want retrieve the settings for that application (the table has got appID as an integer) and then put it in an array or collection with the properties that I specify... then on the client side I want to call this class and then iterate through the settings and use them...

    How can I do this? I have been googling but I can't find anything

    Thanks alot in advance!

  2. #2

    Thread Starter
    Addicted Member Tjoppie's Avatar
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    241

    Re: [2005] Implementing IEnumerator in Web Service

    Hi there everyone...

    I found some code on codeproject on hou to implement what I want to do so I think I am almost there, but now I need to get some info on how to get the values in and out of sql server....
    This is the code that I got and how I customised it to what I want...




    Code:
    Public Class AppSetting 
        Private sID As Integer 'ID 
        Private sName As String 
        Private sValue As String 
    
    
        Public Property ID() 
            Get 
                Return sID 
            End Get 
            Set(ByVal value) 
                sID = value 
            End Set 
        End Property 
        Public Property Name() 
            Get 
                Return sName 
            End Get 
            Set(ByVal value) 
                sName = value 
            End Set 
        End Property 
        Public Property Value() 
            Get 
                Return sValue 
            End Get 
            Set(ByVal value) 
                sValue = value 
            End Set 
        End Property 
    
        Public Sub New() 
            'DEFAULT CONSTRUCTER 
            sName = "" 
            sID = 0 
            sValue = "" 
        End Sub 
    
        Public Sub New(ByVal Name As String, ByVal Value As String) 
            sName = Name 
            sValue = Value 
        End Sub 
    
    End Class 
    
    Public Class AppSettingsCollection 
        Implements IEnumerable, IEnumerator 
        Private iIndex As Integer 'index of the array 
        Private iCount As Integer 'count of the elements 
        Private oSetting() As AppSetting 'array of employee objects 
    
        Public Sub New(ByVal oS() As AppSetting) 
            'any employees? 
            If oS Is Nothing Then 
                'the heck man..hook me up 
                Throw New Exception("No Settings Found") 
            Else 
                iCount = oS.Length - 1 'store the count 
                iIndex = -1 'make sure you don't start at 0...the for each statement as a collection makes a call to MoveNext which increments the index 
                oSetting = oS 'change handles 
            End If 
        End Sub 
    
        Public Function GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator 
            Return Me 'returns an IEnumerator 
        End Function 
    
        Public ReadOnly Property Current() As Object Implements System.Collections.IEnumerator.Current 
            Get 
                Return oSetting(iIndex) 'return the current object at index iIndex 
            End Get 
        End Property 
    
        Public Function MoveNext() As Boolean Implements System.Collections.IEnumerator.MoveNext 
            'returns true if we can move to the next element 
            If iIndex < iCount Then 
                iIndex += 1 
                MoveNext = True 
            Else 
                MoveNext = False 
            End If 
        End Function 
    
        Public Sub Reset() Implements System.Collections.IEnumerator.Reset 
            iIndex = -1 'make sure we start at -1..reasons above 
        End Sub 
    End Class


    Can anyone direct me to where I can do this? Google has got nothing for me for databases...

    Thanks alot in advance

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