none
DataAccessLayer is not recognizing the the class that contains list? RRS feed

  • Question

  • Public Class Class1
        Public Function GetMachineList() As List(Of WcfService1.Machine) class is not recognizing , but other functions are working fine 
            Dim oConn As New Informix("xxxxx;")
            Dim machines As New List(Of Machine)()
            Dim strSql As String = "SELECT k_koneno AS ma_machineid,k_paikka AS ma_placenumber,k_malli AS ma_model,k_tyyppi AS ma_type,k_versio AS ma_version FROM kone"


            Try
                oConn.OpenDB()
                Dim reader = oConn.SelectQueryIntoReader(strSql)
                If reader IsNot Nothing Then
                    While reader.Read()
                        Dim machine As New Machine()
                        machine.ma_machineid = reader.GetString(0)
                        machine.ma_placenumber = reader.GetString(1)
                        machine.ma_model = reader.GetString(2)
                        machine.ma_type = reader.GetString(3)
                        machine.ma_version = reader.GetString(4)
                        machines.Add(machine)
                    End While
                End If
                Return machines

            Catch ex As Exception
                Throw New System.Exception(ex.Message)
            Finally
                oConn.CloseDB()
            End Try

        End Function
        Public Function GetLastName() As String

            Dim oConn As New Informix("xxxxx")

            Dim oo As String

            Try
                oConn.OpenDB()
                oo = oConn.GetFirstValue("select p_fornamn from person where p_efternamn = 'JATOI'").ToString
                Return oo.ToString

            Catch ex As Exception
                Throw New System.Exception(ex.Message)
            Finally
                oConn.CloseDB()
            End Try


        End Function

        Public Function GetPersonsTable() As DataSet
            Dim oConn As New Informix("xxx")

            Dim daTable As New DataTable
            Dim dsTable As New DataSet


            Try
                oConn.OpenDB()


                Dim person = oConn.SelectQueryIntoTable("SELECT k_koneno AS ma_machineid, k_paikka AS ma_placenumber, k_malli AS ma_model,k_tyyppi AS ma_type, k_versio AS ma_version FROM kone WHERE k_paikka = 18 AND k_autmod = 'A'", daTable)

                dsTable.Tables.Add(daTable)
                Return dsTable

            Catch ex As Exception
                Throw New System.Exception(ex.Message)

            Finally
                oConn.CloseDB()

            End Try



        End Function

      <OperationContract()>
        Function GetMachineList() As List(Of Machine)

    <DataContract()>
    Public Class Machine
        Public Property MachineId() As String
            Get
                Return mma_machineid
            End Get

            Set(ByVal value As String)
                mma_machineid = value

            End Set
        End Property
        Private mma_machineid As String


        Public Property MachinePlaceNumber() As String
            Get
                Return mma_placenumber
            End Get
            Set(ByVal value As String)
                mma_placenumber = value
            End Set
        End Property
        Private mma_placenumber As String

        Public Property MachineModel() As String
            Get
                Return mma_model
            End Get
            Set(ByVal value As String)
                mma_model = value
            End Set
        End Property
        Private mma_model As String

        Public Property MachineType() As String
            Get
                Return mma_type
            End Get
            Set(ByVal value As String)
                mma_type = value
            End Set
        End Property
        Private mma_type As String
        Public Property MachineVersion() As String
            Get
                Return mma_version
            End Get
            Set(ByVal value As String)
                mma_version = value
            End Set
        End Property
        Private mma_version As String
    End Class

    all other functions are working fine only the Machine class is not recognizing by class1.vb. please help please

    Wednesday, August 6, 2014 12:07 PM

Answers

  • In the unformatted code you have posted, you have put the Machine class inside Class1. You should define it as a standalone class, i.e. move it outside Class1:

    Public Class Class1
        Public Function GetMachineList() As List(Of WcfService1.Machine) class is not recognizing , but other functions are working fine 
            Dim oConn As New Informix("xxxxx;")
            Dim machines As New List(Of Machine)()
            Dim strSql As String = "SELECT k_koneno AS ma_machineid,k_paikka AS ma_placenumber,k_malli AS ma_model,k_tyyppi AS ma_type,k_versio AS ma_version FROM kone"
    
    
            Try
                oConn.OpenDB()
                Dim reader = oConn.SelectQueryIntoReader(strSql)
                If reader IsNot Nothing Then
                    While reader.Read()
                        Dim machine As New Machine()
                        machine.ma_machineid = reader.GetString(0)
                        machine.ma_placenumber = reader.GetString(1)
                        machine.ma_model = reader.GetString(2)
                        machine.ma_type = reader.GetString(3)
                        machine.ma_version = reader.GetString(4)
                        machines.Add(machine)
                    End While
                End If
                Return machines
    
            Catch ex As Exception
                Throw New System.Exception(ex.Message)
            Finally
                oConn.CloseDB()
            End Try
    
        End Function
        Public Function GetLastName() As String
    
            Dim oConn As New Informix("xxxxx")
    
            Dim oo As String
    
            Try
                oConn.OpenDB()
                oo = oConn.GetFirstValue("select p_fornamn from person where p_efternamn = 'JATOI'").ToString
                Return oo.ToString
    
            Catch ex As Exception
                Throw New System.Exception(ex.Message)
            Finally
                oConn.CloseDB()
            End Try
    
    
        End Function
    
        Public Function GetPersonsTable() As DataSet
            Dim oConn As New Informix("xxx")
    
            Dim daTable As New DataTable
            Dim dsTable As New DataSet
    
    
            Try
                oConn.OpenDB()
    
    
                Dim person = oConn.SelectQueryIntoTable("SELECT k_koneno AS ma_machineid, k_paikka AS ma_placenumber, k_malli AS ma_model,k_tyyppi AS ma_type, k_versio AS ma_version FROM kone WHERE k_paikka = 18 AND k_autmod = 'A'", daTable)
    
                dsTable.Tables.Add(daTable)
                Return dsTable
    
            Catch ex As Exception
                Throw New System.Exception(ex.Message)
    
            Finally
                oConn.CloseDB()
    
            End Try
    
    
        End Function
    
    
        <OperationContract()>
        Function GetMachineList() As List(Of Machine)
            'your implemenation...
        End Function
    End Class
    
    
    <DataContract()>
    Public Class Machine
        Public Property MachineId() As String
            Get
                Return mma_machineid
            End Get
    
            Set(ByVal value As String)
                mma_machineid = value
    
            End Set
        End Property
        Private mma_machineid As String
    
    
        Public Property MachinePlaceNumber() As String
            Get
                Return mma_placenumber
            End Get
            Set(ByVal value As String)
                mma_placenumber = value
            End Set
        End Property
        Private mma_placenumber As String
    
        Public Property MachineModel() As String
            Get
                Return mma_model
            End Get
            Set(ByVal value As String)
                mma_model = value
            End Set
        End Property
        Private mma_model As String
    
        Public Property MachineType() As String
            Get
                Return mma_type
            End Get
            Set(ByVal value As String)
                mma_type = value
            End Set
        End Property
        Private mma_type As String
        Public Property MachineVersion() As String
            Get
                Return mma_version
            End Get
            Set(ByVal value As String)
                mma_version = value
            End Set
        End Property
        Private mma_version As String
    End Class
    

    As I also told you in the other thread, you have to upload a reproducable sample of your issue to OneDrive or similar for anyone to be able to help you if you cannot solve the issue from here. I am afraid we cannot guess what you are doing wrong on your side.

    Wednesday, August 6, 2014 12:31 PM

All replies

  • datalogic 

    class 1.vb

    Public Class Class1
        Public Function GetMachineList() As List(Of WcfService1.Machine) class is not recognizing , but other functions are working fine 
            Dim oConn As New Informix("xxxxx;")
            Dim machines As New List(Of Machine)()
            Dim strSql As String = "SELECT k_koneno AS ma_machineid,k_paikka AS ma_placenumber,k_malli AS ma_model,k_tyyppi AS ma_type,k_versio AS ma_version FROM kone"


            Try
                oConn.OpenDB()
                Dim reader = oConn.SelectQueryIntoReader(strSql)
                If reader IsNot Nothing Then
                    While reader.Read()
                        Dim machine As New Machine()
                        machine.ma_machineid = reader.GetString(0)
                        machine.ma_placenumber = reader.GetString(1)
                        machine.ma_model = reader.GetString(2)
                        machine.ma_type = reader.GetString(3)
                        machine.ma_version = reader.GetString(4)
                        machines.Add(machine)
                    End While
                End If
                Return machines

            Catch ex As Exception
                Throw New System.Exception(ex.Message)
            Finally
                oConn.CloseDB()
            End Try

        End Function
        Public Function GetLastName() As String

            Dim oConn As New Informix("xxxxx")

            Dim oo As String

            Try
                oConn.OpenDB()
                oo = oConn.GetFirstValue("select p_fornamn from person where p_efternamn = 'JATOI'").ToString
                Return oo.ToString

            Catch ex As Exception
                Throw New System.Exception(ex.Message)
            Finally
                oConn.CloseDB()
            End Try


        End Function

        Public Function GetPersonsTable() As DataSet
            Dim oConn As New Informix("xxx")

            Dim daTable As New DataTable
            Dim dsTable As New DataSet


            Try
                oConn.OpenDB()


                Dim person = oConn.SelectQueryIntoTable("SELECT k_koneno AS ma_machineid, k_paikka AS ma_placenumber, k_malli AS ma_model,k_tyyppi AS ma_type, k_versio AS ma_version FROM kone WHERE k_paikka = 18 AND k_autmod = 'A'", daTable)

                dsTable.Tables.Add(daTable)
                Return dsTable

            Catch ex As Exception
                Throw New System.Exception(ex.Message)

            Finally
                oConn.CloseDB()

            End Try



        End Function

        Public Function GetPersonsTest() As DataSet
            Dim oConn As New Informix("xxxxx")

            Dim daTable As New DataTable
            Dim dsTable As New DataSet


            Try
                oConn.OpenDB()


                Dim person = oConn.SelectQueryIntoTable("SELECT * from person", daTable)

                dsTable.Tables.Add(daTable)
                Return dsTable

            Catch ex As Exception
                Throw New System.Exception(ex.Message)

            Finally
                oConn.CloseDB()

            End Try



        End Function
    End Class

    wcf service1

    Iservice1.Vb

        

    Imports System.Web.Script.Services

    ' NOTE: You can use the "Rename" command on the context menu to change the interface name "IService1" in both code and config file together.
    <ServiceContract()>
    Public Interface IService1

        <OperationContract()>
             <WebInvoke(Method:="Get",
                         ResponseFormat:=WebMessageFormat.Json,
                BodyStyle:=WebMessageBodyStyle.Wrapped,
                UriTemplate:="GetDataJSON")> _
        Function GetData(ByVal value As Integer) As String


        <OperationContract()>
        Function GetPersonTable() As DataSet

        <OperationContract()>
        Function GetPersonTest() As DataSet

        <OperationContract()>
        Function GetMachineList() As List(Of Machine)




        <OperationContract()>
        Function GetDataUsingDataContract(ByVal composite As CompositeType) As CompositeType

        ' TODO: Add your service operations here

    End Interface

    ' Use a data contract as illustrated in the sample below to add composite types to service operations.

    <DataContract()>
    Public Class CompositeType

        <DataMember()>
        Public Property BoolValue() As Boolean

        <DataMember()>
        Public Property StringValue() As String

    End Class

    <DataContract()>
    Public Class Machine
        Public Property MachineId() As String
            Get
                Return mma_machineid
            End Get

            Set(ByVal value As String)
                mma_machineid = value

            End Set
        End Property
        Private mma_machineid As String


        Public Property MachinePlaceNumber() As String
            Get
                Return mma_placenumber
            End Get
            Set(ByVal value As String)
                mma_placenumber = value
            End Set
        End Property
        Private mma_placenumber As String

        Public Property MachineModel() As String
            Get
                Return mma_model
            End Get
            Set(ByVal value As String)
                mma_model = value
            End Set
        End Property
        Private mma_model As String

        Public Property MachineType() As String
            Get
                Return mma_type
            End Get
            Set(ByVal value As String)
                mma_type = value
            End Set
        End Property
        Private mma_type As String
        Public Property MachineVersion() As String
            Get
                Return mma_version
            End Get
            Set(ByVal value As String)
                mma_version = value
            End Set
        End Property
        Private mma_version As String
    End Class

    Service1.Vb

    Public Class Service1
        Implements IService1

        Public Sub New()
        End Sub

        Public Function GetData(ByVal value As Integer) As String Implements IService1.GetData
         
            Dim oDL As New Datalogic.Class1
            Return oDL.GetLastName
            

        End Function


        Public Function GetPersonTable() As DataSet Implements IService1.GetPersonTable
       
            Dim oDL As New Datalogic.Class1
            Return oDL.GetPersonsTable


        End Function

        Public Function GetPersonTest() As DataSet Implements IService1.GetPersonTest
        
            Dim oDL As New Datalogic.Class1
            Return oDL.GetPersonsTest


        End Function

        Public Function GetMachineList() As List(Of Machine) Implements IService1.GetMachineList

      
      
        Dim oDL As New Datalogic.Class1
            Return oDL.GetMachineList


        End Function






        Public Function GetDataUsingDataContract(ByVal composite As CompositeType) As CompositeType Implements IService1.GetDataUsingDataContract
            If composite Is Nothing Then
                Throw New ArgumentNullException("composite")
            End If
            If composite.BoolValue Then
                composite.StringValue &= "Suffix"
            End If
            Return composite
        End Function

    End Class

    ALL OTHER FUNCIONS ARE WORKING FINE BUT ONLY THE Public Function GetMachineList() As List(Of WcfService1.Machine) class SHOWING ERROR NOW PLEASE HELP i spent days on it.

    and i have made reference other functions are working fine but machine list is not working fine

    Wednesday, August 6, 2014 6:11 AM
  • Where is the Machine class defined? As I told you in the other thread (http://social.msdn.microsoft.com/Forums/vstudio/en-US/4d59775b-a785-4a71-9794-6e1989f01079/how-can-i-connect-one-class-file-to-another-project-as-reference?forum=wcf), you need to add a reference to the project where the Machine class is defined from the datalogic project (right-click on the datalogic project in Solution Explorer->"Add reference"->Solution->Projects->"WcfService1 (or whatever the project where the Machine class resides is called)).

    If you put the cursor right next to "Machine" in Visual Studio and then press [CTRL]+[.] on the keyboard, you should get a dialog that lets you import the namespace of the Machine class. Click on the "Import.." link. This assumes that you have added the reference correctly first though: http://msdn.microsoft.com/en-us/library/vstudio/f3st0d45(v=vs.100).aspx

    Please don't ask the same question in several threads and please remeber to mark any helpful posts as answer and/or helpful.

    Wednesday, August 6, 2014 12:18 PM
  • Where is the Machine class defined? As I told you in the other thread (http://social.msdn.microsoft.com/Forums/vstudio/en-US/4d59775b-a785-4a71-9794-6e1989f01079/how-can-i-connect-one-class-file-to-another-project-as-reference?forum=wcf), you need to add a reference to the project where the Machine class is defined from the datalogic project (right-click on the datalogic project in Solution Explorer->"Add reference"->Solution->Projects->"WcfService1 (or whatever the project where the Machine class resides is called)).

    If you put the cursor right next to "Machine" in Visual Studio and then press [CTRL]+[.] on the keyboard, you should get a dialog that lets you import the namespace of the Machine class. Click on the "Import.." link. This assumes that you have added the reference correctly first though: http://msdn.microsoft.com/en-us/library/vstudio/f3st0d45(v=vs.100).aspx

    Please don't ask the same question in several threads and please remeber to mark any helpful posts as answer and/or helpful.

    Wednesday, August 6, 2014 12:18 PM
  • other functions in the same class is working but it is not recognizing the machine class?

    i am trying to tackle it from 7 days but its not working

     
    Wednesday, August 6, 2014 12:25 PM
  • In the unformatted code you have posted, you have put the Machine class inside Class1. You should define it as a standalone class, i.e. move it outside Class1:

    Public Class Class1
        Public Function GetMachineList() As List(Of WcfService1.Machine) class is not recognizing , but other functions are working fine 
            Dim oConn As New Informix("xxxxx;")
            Dim machines As New List(Of Machine)()
            Dim strSql As String = "SELECT k_koneno AS ma_machineid,k_paikka AS ma_placenumber,k_malli AS ma_model,k_tyyppi AS ma_type,k_versio AS ma_version FROM kone"
    
    
            Try
                oConn.OpenDB()
                Dim reader = oConn.SelectQueryIntoReader(strSql)
                If reader IsNot Nothing Then
                    While reader.Read()
                        Dim machine As New Machine()
                        machine.ma_machineid = reader.GetString(0)
                        machine.ma_placenumber = reader.GetString(1)
                        machine.ma_model = reader.GetString(2)
                        machine.ma_type = reader.GetString(3)
                        machine.ma_version = reader.GetString(4)
                        machines.Add(machine)
                    End While
                End If
                Return machines
    
            Catch ex As Exception
                Throw New System.Exception(ex.Message)
            Finally
                oConn.CloseDB()
            End Try
    
        End Function
        Public Function GetLastName() As String
    
            Dim oConn As New Informix("xxxxx")
    
            Dim oo As String
    
            Try
                oConn.OpenDB()
                oo = oConn.GetFirstValue("select p_fornamn from person where p_efternamn = 'JATOI'").ToString
                Return oo.ToString
    
            Catch ex As Exception
                Throw New System.Exception(ex.Message)
            Finally
                oConn.CloseDB()
            End Try
    
    
        End Function
    
        Public Function GetPersonsTable() As DataSet
            Dim oConn As New Informix("xxx")
    
            Dim daTable As New DataTable
            Dim dsTable As New DataSet
    
    
            Try
                oConn.OpenDB()
    
    
                Dim person = oConn.SelectQueryIntoTable("SELECT k_koneno AS ma_machineid, k_paikka AS ma_placenumber, k_malli AS ma_model,k_tyyppi AS ma_type, k_versio AS ma_version FROM kone WHERE k_paikka = 18 AND k_autmod = 'A'", daTable)
    
                dsTable.Tables.Add(daTable)
                Return dsTable
    
            Catch ex As Exception
                Throw New System.Exception(ex.Message)
    
            Finally
                oConn.CloseDB()
    
            End Try
    
    
        End Function
    
    
        <OperationContract()>
        Function GetMachineList() As List(Of Machine)
            'your implemenation...
        End Function
    End Class
    
    
    <DataContract()>
    Public Class Machine
        Public Property MachineId() As String
            Get
                Return mma_machineid
            End Get
    
            Set(ByVal value As String)
                mma_machineid = value
    
            End Set
        End Property
        Private mma_machineid As String
    
    
        Public Property MachinePlaceNumber() As String
            Get
                Return mma_placenumber
            End Get
            Set(ByVal value As String)
                mma_placenumber = value
            End Set
        End Property
        Private mma_placenumber As String
    
        Public Property MachineModel() As String
            Get
                Return mma_model
            End Get
            Set(ByVal value As String)
                mma_model = value
            End Set
        End Property
        Private mma_model As String
    
        Public Property MachineType() As String
            Get
                Return mma_type
            End Get
            Set(ByVal value As String)
                mma_type = value
            End Set
        End Property
        Private mma_type As String
        Public Property MachineVersion() As String
            Get
                Return mma_version
            End Get
            Set(ByVal value As String)
                mma_version = value
            End Set
        End Property
        Private mma_version As String
    End Class
    

    As I also told you in the other thread, you have to upload a reproducable sample of your issue to OneDrive or similar for anyone to be able to help you if you cannot solve the issue from here. I am afraid we cannot guess what you are doing wrong on your side.

    Wednesday, August 6, 2014 12:31 PM
  • thanks alot for your quick response , i am very thankful of you.

    here is the link of file: 

    https://onedrive.live.com/edit.aspx?resid=8152CBCED551893A%21108&nd=1&app=Word

    Wednesday, August 6, 2014 12:38 PM
  • i am waiting for you reply

    here is the link of file: 

    https://onedrive.live.com/edit.aspx?resid=8152CBCED551893A%21108&nd=1&app=Word

    Wednesday, August 6, 2014 1:02 PM
  • i am waiting for you reply

    What you have is a  DTO it should be called DtoMachine. The WCF client and the WCF service are two different processes passing information between each other.

    http://en.wikipedia.org/wiki/Data_transfer_object

    <copied>

    Data transfer object (DTO)<sup class="reference" id="cite_ref-msdn_1-0">[</sup> is an object that carries data between processes

    <end>

    You have the Machine class that has unnecessary backing private vaiables for properties, which can be eliminated by using auto-properties.

    http://msdn.microsoft.com/en-us/library/dd293589.aspx

    <copied>

    Auto-implemented properties enable you to quickly specify a property of a class without having to write code to Get and Set the property. When you write code for an auto-implemented property, the Visual Basic compiler automatically creates a private field to store the property variable in addition to creating the associated Get and Set procedures.

    <end>

    If you make a classlib project in the solution called Entities, you can create the DtoMachine class in the Entities project that is using the DataContract and Datamember (Datamember above public properties) in the DtoMachine object. 

    The WCF client project and the WCF service project can set project reference to the Entities project, and the client and service will know what DtoMachine is about.

    Wednesday, August 6, 2014 1:28 PM