웹 서비스 노출을 위해 Dal을 건축하는 방법은 무엇입니까?
-
04-07-2019 - |
문제
우리는 우리의 DB에 자리한 고도로 전문화 된 DAL을 가지고 있습니다. 우리의 앱은이 DAL을 사용 하여이 DB에 대해 올바르게 작동해야합니다.
생성 된 DAL (일부 사용자 정의 기본 클래스에 위치)에는 각각의 주어진 테이블의 레코드 구조를 나타내는 다양한 'Rec'클래스 (표 1Rec, Table2Rec)가 있습니다.
다음은 샘플 의사 클래스입니다 ...
Public Class SomeTableRec
Private mField1 As String
Private mField1isNull As Boolean
Private mField2 As Integer
Private mField2isNull As Boolean
Public Sub New()
mField1isNull = True
mField2isNull = True
End Sub
Public Property Field1() As String
Get
Return mField1
End Get
Set(ByVal value As String)
mField1 = value
mField1isNull = False
End Set
End Property
Public ReadOnly Property Field1isNull() As Boolean
Get
Return mField1isNull
End Get
End Property
Public Property Field2() As Integer
Get
Return mField2
End Get
Set(ByVal value As Integer)
mField2 = value
mField2isNull = False
End Set
End Property
Public ReadOnly Property Field2isNull() As Boolean
Get
Return mField2isNull
End Get
End Property
End Class
각 클래스에는 각 필드에 대한 속성이 있습니다 ... 따라서 쓸 수 있습니다 ...
Dim Rec as New Table1Rec
Table1Rec.Field1 = "SomeString"
Table2Rec.Field2 = 500
필드가 널 값을 수용 할 수있는 경우, 값이 현재 널이 있는지 여부를 나타내는 추가 특성이 있습니다.
따라서....
Dim Rec as New Table1Rec
Table1Rec.Field1 = "SomeString"
If Table1Rec.Field1Null then
' This clearly is not true
End If
If Table1Rec.Field2Null then
' This will be true
End If
클래스의 생성자는 모든 nullproperties를 true로 설정하고 FieldProperty의 설정으로 인해 동등한 NullProperty가 False로 설정되기 때문에 작동합니다.
최근에 웹 서비스를 통해 웹을 통해 내 DAL을 노출시켜야 할 필요가 있었으며 (물론 보안하려고합니다) 'Rec'클래스의 구조가 웹을 통해 그대로 유지되는 동안 ... 모든 논리는 잃어버린..
누군가가 이전 코드 조각을 원격으로 실행한다면 클라이언트 부수적 코드가 없기 때문에 어떤 조건도 사실이 증명되지 않을 것임을 알지 못할 것입니다.
나는이 모든 것을 잘못 구조 한 느낌을 얻지 만 어떻게 개선 해야하는지 볼 수는 없습니다.
이것을 건축하는 올바른 방법은 무엇입니까?
해결책
질문을 완전히 이해하는지 확실하지 않지만 XML에서 무효화 가능한 데이터 유형을 가질 수 있습니다.
그래서 이거...
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class Testing
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function GetObjects() As Generic.List(Of TestObject)
Dim list As New Generic.List(Of TestObject)
list.Add(New TestObject(Nothing, "Empty ID Object"))
list.Add(New TestObject(1, "Full ID Object"))
list.Add(New TestObject(2, Nothing))
Return list
End Function
Public Class TestObject
Public Sub New()
_name = String.Empty
_id = Nothing
End Sub
Public Sub New(ByVal id As Nullable(Of Integer), ByVal name As String)
_name = name
_id = id
End Sub
Private _name As String
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Private _id As Nullable(Of Integer)
Public Property ID() As Nullable(Of Integer)
Get
Return _id
End Get
Set(ByVal value As Nullable(Of Integer))
_id = value
End Set
End Property
End Class
End Class
이것을 출력합니다 (무효 지역 포함)
<?xml version="1.0" encoding="utf-8" ?>
<ArrayOfTestObject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<TestObject>
<Name>Empty ID Object</Name>
<ID xsi:nil="true" />
</TestObject>
<TestObject>
<Name>Full ID Object</Name>
<ID>1</ID>
</TestObject>
<TestObject>
<ID>2</ID>
</TestObject>
</ArrayOfTestObject>
다른 팁
웹 서비스는 운영 (방법) 및 데이터 계약을 노출 시키도록 설계되었지만 내부 구현 로직은 아닙니다. 이것은 서비스 지향 아키텍처 세계에서 "좋은 것"입니다. 설명하는 시나리오는 원격/분산 객체 아키텍처입니다. 웹 서비스는 귀하가하려는 일을 지원하지 않습니다. 이것을 참조하십시오 게시하다 자세한 내용은.