Доступ к библиотеке классов в WCF - PullRequest
1 голос
/ 30 июня 2011

У меня есть два класса в двух файлах в проекте библиотеки классов:

Public Class Logins
    Public CurrentUser As Login
    Public Function Authenticate(ByVal id As String, ByVal pw As String)
        Dim adpt As New WorkMateDataSetTableAdapters.LoginsTableAdapter
        For Each k As WorkMateDataSet.LoginsRow In adpt.GetDataByUserName(id)
            If String.Equals(k.UserPW, pw) Then
                CurrentUser = New Login(k.UserName, k.UserPW, k.UserType)
                Return CurrentUser
                Exit Function
            End If
        Next
        CurrentUser = Nothing
        Return Nothing
    End Function
End Class

Public Class Login
    Private _UserName As String
    Private _UserPW As String
    Private _UserType As String

    Property UserName
        Get
            Return _UserName
        End Get
        Set(value)
            _UserName = value
        End Set
    End Property
    Property UserPW
        Get
            Return _UserPW
        End Get
        Set(value)
            _UserPW = value
        End Set
    End Property
    Property UserType
        Get
            Return _UserType
        End Get
        Set(value)
            _UserType = value
        End Set
    End Property
    Public Sub New()
        UserName = ""
        UserPW = ""
        UserType = ""
    End Sub
    Public Sub New(ByVal Namee As String, ByVal pw As String, ByVal typee As String)
        UserName = Namee
        UserPW = pw
        UserType = typee
    End Sub

End Class

другой класс:

public Class Courses
    Public CoursesOffered As List(Of Course)
End Class

Public Class Course
    'Cource name, Exams, Papers
    Private _CourseCategory As String
    Private _CourseID As String
    Public _Sems As New List(Of Sem)
End Class

Я использовал службу WCF, используя net.Однако при tcp-соединении проблема заключается в том, что я могу использовать исходные классы для входа в систему напрямую, например (Public Logins As New ServiceLogins.Logins), но я не могу использовать такой класс курса.код для двух служб WCF:

Imports System.ServiceModel
<ServiceContract()>
Public Interface IService1

    <OperationContract()>
    Function Test(ByVal value As Integer) As WorkMateLib.Course

    <OperationContract()>
    Function GetData(ByVal value As Integer) As String

    ' TODO: Add your service operations here

End Interface

and the other file is:


Imports System.ServiceModel

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

    <OperationContract()>
    Function Authentication(ByVal login As WorkMateLib.Login) As WorkMateLib.Login

End Interface

Благодарим Вас за помощь в этом вопросе.Спасибо.

Редактировать:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service name="WorkMateWCF.WorkMateWCFService1">
        <endpoint address="" binding="netTcpBinding" bindingConfiguration=""
          contract="WorkMateWCF.IService1">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
          contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:8523/WorkMateWCFServiceHost" />
          </baseAddresses>
        </host>
      </service>
      <service name="WorkMateWCF.LoginsRelated">
        <endpoint address="" binding="netTcpBinding" bindingConfiguration=""
          contract="WorkMateWCF.ILoginsRelated">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
          contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:8732/WCFLoginsHost" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="false" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

</configuration>

1 Ответ

0 голосов
/ 30 июня 2011

Не совсем ясно, чего вы пытаетесь достичь, но класс Course предоставляет только одно открытое свойство с именем _sem , которое WCF будет сериализовать как массив объектов типа Sem. У вас не должно возникнуть проблем с использованием типа «Курсы» в коде обслуживания, но, поскольку он не является частью договора на обслуживание, он недоступен для клиентов, использующих этот договор на обслуживание.

EDIT:

Чтобы сделать курсы доступными для клиентов, вы можете сделать что-то вроде этого:

 '''''''Rest of contract snipped

 <OperationContract()>
 Function GetCourses() As WorkMateLib.Courses

 '''''''Rest of contract snipped

Ключ заключается в том, чтобы добавить любой класс в службу, которую вы хотите открыть для клиентской части контракта на обслуживание, путем ссылки на него в качестве входного параметра или выходного значения операции службы (функции).

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...