none
how can i connect one class file to another project as reference? RRS feed

  • Question

  • i have one datalogic project in there class1.vb, where i am getting list of records from the database.

    another i have wcfservice1 in the Iservice1.vb i am defining the class(of list)?

    and third i have window form application where i am getting the output

    how can i connect my DataContract class to Class1.vb???????

    Monday, August 4, 2014 10:58 AM

Answers

All replies

  • What do you mean by "connect"? In order for you to be able to use class1.vb in the wcfservice1 project, or any other project, you should add a reference to the datalogic project from the wcfservice project. Please refer to the "Adding a Project Reference in Visual Studio" on the following page for information about how to this: http://msdn.microsoft.com/en-us/library/vstudio/f3st0d45(v=vs.100).aspx

    Once you have added the reference, you can use the class that is defined in the referenced project by its namespace and name, e.g.:

    Dim myClass As datalogic.class1

    ...where datalogic is the namespace of the class and class1 is the name of the class. You can see what the default namespace for your class library is by looking at the "Default namespace:" TextBox after right-clicking on the project in the Solution Explorer and selecting "Properties".


    Monday, August 4, 2014 11:11 AM
  • i have class1.vb in DataLogic Project

    Public Function MachineList() As List(Of Machine) // here is showing error on machine
            Dim oConn As New Informix("xxxxxxxxxxxxxxxxx")
            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 List(Of 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

    i have another wcfservice1 project

    Iservice1.vb

       

     <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

    service1.cs

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

      Dim oDL As New Datalogic.Class1
            Return oDL.MachineList()


        End Function

    please help me it is not recognizing my machine class?

    i spend days on it please help me

    Monday, August 4, 2014 11:29 AM
  • If the Machine class is defined in the wcfservice1 project, you need to add a reference to this project from the DataLogic project to be able to use it. Also, as mentioned, you need to know the name of the namespace in which the Machine class is defined, it is usually the name of the project:

    Public Function MachineList() As List(Of wcfservice1.Machine) // here is showing error on machine
    

    Monday, August 4, 2014 11:42 AM
  • i used

    Public Function MachineList() As List(Of wcfservice1.IService.Machine)

    and

    Public Function MachineList() As List(Of wcfservice1.Machine)

    both are not working what should i do now?


    Monday, August 4, 2014 12:27 PM
  • Did you add the reference to the wcfservice project from the DataLogic project as I suggested?

    Please upload your project to OneDrive or similar and post the link to it here if you need any further help.

    Monday, August 4, 2014 12:31 PM
  • datalogic 

    class 1.vb

    Public Class Class1
        Public Function GetMachineList() As List(Of WcfService1.Machine)
            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) SHOWING ERROR NOW PLEASE HELP


    Monday, August 4, 2014 12:46 PM
  • please reply
    Monday, August 4, 2014 1:26 PM
  • Hi,

    It seems that you have solved your problem in here:
    http://social.msdn.microsoft.com/Forums/en-US/8ab025e9-540d-413f-a30a-8cfbf8bf7c1e/dataaccesslayer-is-not-recognizing-the-the-class-that-contains-list .
    Then it will help the others who meet the same question as you, if you have any other problem, welcome to post it to this Forum.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, August 7, 2014 2:34 AM
    Moderator