我有WCF C#类向花药类返回两个值,它工作正常,但是我需要在vb.net中使用相同的代码,因此我将C#转换为vb.net在线站点,结果 vb代码:
<WebMethod(MessageName:="OpenAccount", Description:="this method create new account in the database"), _
System.Xml.Serialization.XmlInclude(GetType(ContactResult))> _
Public Function OpenAccount(ByVal Num As String, ByVal Pass As String) As ContactResult
Dim ds As New DataSet
Dim cr As New ContactResult
Try
Dim data As String
Dim openCon As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\MONZER\Desktop\Karary Web Site\WebApplication1\App_Data\Database1.mdf;Integrated Security=True;User Instance=True")
Dim da As SqlDataAdapter = New SqlDataAdapter("select * from Password", openCon)
Dim saveStaff As String = "select Spec from Password where Num = @AndroidNum AND Pass = @AndroidPass"
Dim querySaveStaff As SqlCommand = New SqlCommand(saveStaff)
querySaveStaff.Connection = openCon
querySaveStaff.Parameters.Clear()
querySaveStaff.Parameters.AddWithValue("@AndroidNum", Num)
querySaveStaff.Parameters.AddWithValue("@AndroidPass", Pass)
openCon.Open()
querySaveStaff.ExecuteNonQuery()
ds.Clear()
da.Fill(ds, "Password")
data = ds.Tables("Password").Rows(0).Item(2).ToString
openCon.Close()
cr.ErrorID = 0
cr.ErrorMessage = "vvvvvvvvvvvvvvvvvvvvv"
Return cr
Catch ex As Exception
cr.ErrorID = 1
cr.ErrorMessage = ex.Message
Return cr
End Try
End Function
将ErrorID和ErrorMessage返回给ContactResult类 ContactResult vb:
Public Class ContactResult
Public Property ErrorID As Integer
Get
End Get
Set(ByVal value As Integer)
End Set
End Property
Public Property ErrorMessage As String
Get
End Get
Set(ByVal value As String)
End Set
End Property
End Class
但是它不起作用,它只是返回没有ErrorMessage的ErrorID,它在浏览器中显示如下:
<ContactResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
0
答案 0 :(得分:1)
您的属性处理程序不执行任何操作。因此,ErrorID保持为0(默认值Integer
),而ErrorMessage保持为null
(默认值string
)。似乎转换器错误地更改了您的Auto-Implemented Properties:
public string PropertyName { get; set; }
到
Public Property PropertyName As String
Get
End Get
Set(ByVal value As String)
End Set
End Property
代替
Public Property PropertyName As String
尝试将ContactResult
切换到
Public Class ContactResult
Public Property ErrorID As Integer
Public Property ErrorMessage As String
End Class