我想我错过了一些非常基本的东西,但这是我的困境。在 VB.net 中,我创建了一个MembershipUser
从 Web 服务继承并返回对象的类:
Public Class ModifiedUser
Inherits MembershipUser
用户登录:
Private Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
Dim ws As New MembersWS.Members
Dim Member As New MembersWS.ModifiedUser
ws.Credentials = System.Net.CredentialCache.DefaultCredentials()
Member = ws.ValidateUser(Login1.UserName, Login1.Password)
End Sub
在 Web 服务中创建对象时,ModifiedUser
包含所有属性MembershipUser
以及新类的属性。
在我的示例中,该ValidateUser
函数验证用户并添加其他属性:
Public Function ValidateUser(ByVal UserName As String, ByVal Password As String) As ModifiedUser
Dim BaseUser As MembershipUser = Membership.Provider.GetUser(UserName, False)
Dim Member As New ModifiedUser
If Membership.Provider.ValidateUser(UserName, Password) = True Then
Member = New ModifiedUser(BaseUser.ProviderName, BaseUser.UserName, BaseUser.ProviderUserKey, BaseUser.Email, BaseUser.PasswordQuestion, BaseUser.Comment, BaseUser.IsApproved, BaseUser.IsLockedOut, BaseUser.CreationDate, BaseUser.LastLoginDate, BaseUser.LastActivityDate, BaseUser.LastPasswordChangedDate, BaseUser.LastLockoutDate, 0, "", "", "", "", True)
' ... (Set new property values)
End if
Return Member
End Function
当Member
返回到Login1_Authenticate
时,只读属性将从对象中删除,同时它们包含在从 Web 服务返回的对象中。
在reference.vb
Web 服务的文件中,自动生成的代码包含一个部分MembershipUser
类,其中仅包含可更新的属性以及关联的 getter 和 setter:
Partial Public Class MembershipUser
Private emailField As String
Private commentField As String
Private isApprovedField As Boolean
Private lastLoginDateField As Date
Private lastActivityDateField As Date
如果有人可以让我知道如何在返回的对象中包含只读属性,我将不胜感激。