如何构建 DAL 以实现 WebService 暴露?
我们有一个高度专业化的 DAL,位于我们的数据库之上。 我们的应用程序需要使用此 DAL 才能针对此数据库正确操作。
生成的 DAL(位于某些自定义基类上)具有各种“Rec”类(Table1Rec、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
在字段可以接受 NULL 值的地方,有一个附加属性指示该值当前是否为 null。
因此......
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
这是有效的,因为类的构造函数将所有 NULL 属性设置为 True,并且任何 FieldProperty 的设置将导致等效的 NullProperty 设置为 false。
我最近需要通过 Web 服务(我当然打算保护它)在 Web 上公开我的 DAL,并且发现虽然“Rec”类的结构在 Web 上保持完整......所有逻辑都是丢失..
如果有人远程运行前一段代码,他们会注意到这两个条件都不会被证明为真,因为没有客户端代码将 null 设置为 true。
我感觉我设计的这一切都是错误的,但不知道我应该如何改进它。
设计这个的正确方法是什么?
We have a highly specialized DAL which sits over our DB. Our apps need to use this DAL to correctly operate against this DB.
The generated DAL (which sits on some custom base classes) has various 'Rec' classes (Table1Rec, Table2Rec) each of which represents the record structure of a given table.
Here is a sample Pseudo-class...
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
Each class has properties for each of the fields...
Thus I can write...
Dim Rec as New Table1Rec
Table1Rec.Field1 = "SomeString"
Table2Rec.Field2 = 500
Where a field can accept a NULL value, there is an additional property which indicates if the value is currently null.
Thus....
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
This works because the constructor of the class sets all NULLproperties to True and the setting of any FieldProperty will cause the equivalent NullProperty to be set to false.
I have recently had the need to expose my DAL over the web through a web service (which I of course intend to secure) and have discovered that while the structure of the 'Rec' class remains intact over the web... All logic is lost..
If someone were to run the previous piece of code remotely they would notice that neither condition would prove true as there is no client side code which sets null to true.
I get the feeling I have architected this all wrong, but cannot see how I should improve it.
What is the correct way to architect this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定我是否完全理解这个问题,但 XML 中可以有可为空的数据类型。
所以这...
输出这个(带有可为空的区域)
Not sure if I fully understand the question, but you can have nullable data types in XML.
So this...
outputs this (with nullable areas)
Web 服务旨在公开操作(方法)和操作(方法)。 数据契约但不是内部实现逻辑。 这在面向服务的架构领域是一件“好事”。 您描述的场景是远程/分布式对象体系结构。 Web 服务将不支持您尝试执行的操作。 请参阅此帖子了解更多信息。
Web services are designed to expose operation(methods) & data contracts but not internal implementation logic. This is a "good thing" in the world of service-oriented architecture. The scenario you describe is a remote/distributed object architecture. Web services will not support what you are trying to do. Please see this post for more information.