我正在尝试在visual studio 2010中创建一个简单的VB Web服务,这是一种音乐播放列表服务。
我曾尝试创建一个函数来检查数据库中是否存在用户但是在运行程序时出现错误'反序列化操作的回复消息的错误'。
以下是调用checkUser函数的客户端登录表单的代码,这是错误似乎发生的地方。
Dim service As New musicPlaylistService.Service1SoapClient("Service1Soap")
Public signinName As String
Dim check As Boolean
Private Sub signInBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles signInBtn.Click
If signInNick.Text = "" Then
MessageBox.Show("Please enter a user name")
signInNick.Focus()
Else
signinName = signInNick.Text
main.Visible = True
Me.Hide()
main.tbxUserName.Text = signInNick.Text
check = service.checkUser(signInNick.Text)
If check = False Then
MessageBox.Show("User has been created")
Else
MessageBox.Show("Thankyou for Signing In ", signInNick.Text)
End If
End If
End Sub
这是服务checkUser函数的代码
'checking if user exists in the system already
<WebMethod()> _
Public Function checkUser(ByVal signinName As String) As String
Dim numrows As Integer
Dim conn As New SqlConnection("Data Source=MARTIN-LAPTOP\SQLEXPRESS;Initial Catalog=musicPlaylist;Integrated Security=True")
Dim sql As String = "SELECT COUNT(*) FROM Users WHERE userNick = ('" & signinName & "')"
conn.Open()
Dim objcmd As New SqlCommand(sql, conn)
numrows = objcmd.ExecuteScalar()
If numrows > 0 Then
getExistingUserPLData(signinName)
Return True
Else
createUser(signinName)
Return False
End If
End Function
当运行程序并且我尝试输入用户名时,错误在反序列化操作'checkUser'的回复消息体中出错。
突出显示 check = service.checkUser(signInNick.Text)
代码行。
在内部异常下单击错误消息的视图详细信息时,我可以看到消息“XML文档中存在错误(1,325)”以及“字符串'True'不是有效的布尔值'< / p>
非常感谢任何帮助或帮助,
感谢