尝试将自定义类返回给用户时出错。当它抛出异常时它应该返回自定义类但我无法做到。
Public Function LoginRequest(ByVal obj As LoginRequest) As LoginResponse Implements ITTMSService.LoginRequest
Dim ReaderID As String
Dim InternalID As String
Dim TransRefDateTime As String
Dim Operator as String
Dim Balance As String
Dim Cryptogram As String
Dim ResponseCode As String
Dim ResponseMsg As String
Dim aLoginResponse As New LoginResponse
Dim aLoginResponseErr As New LoginResponseEx
Dim response = ws2.login(ReaderID, InternalID, TransRef, TransRefDateTime, [Operator], Balance, Cryptogram, ResponseCode, ResponseMsg)
If ResponseCode = "00" Then
With aLoginResponse
.ReaderID = ReaderID
.Cryptogram = Cryptogram
.TransDateTime = TransRefDateTime
.ResponseCode = ResponseCode
End With
Return aLoginResponse
Else
With aLoginResponseErr
.ReaderID = ReaderID
.Cryptogram = Cryptogram
.TransDateTime = TransRefDateTime
.ResponseCode = ResponseCode
.ResponseMsg = ResponseMsg
End With
Return aLoginResponseErr
End If
Return Nothing
End Function
班级:
#Region "LoginResponse"
<DataContract([Namespace]:="")>
Public Class LoginResponse
<DataMember()> _
Public Property TerminalID As String
<DataMember()> _
Public Property ReaderID As String
<DataMember()> _
Public Property TransRef As String
<DataMember()> _
Public Property TransDateTime As String
<DataMember()> _
Public Property Timeout As Integer
<DataMember()> _
Public Property ResponseCode As String
<DataMember()> _
Public Property Cryptogram As String
End Class
#End Region
#Region "LoginResponseEx"
<DataContract([Namespace]:="")>
Public Class LoginResponseEx : Inherits LoginResponse
<DataMember()>
Public Property ResponseMsg As String
End Class
#End Region
返回LoginResponseErr类时出错。请hielp。感谢
Failed to invoke the service. Possible causes: The service is offline or inaccessible; the client-side configuration does not match the proxy; the existing proxy is invalid. Refer to the stack trace for more detail. You can try to recover by starting a new proxy, restoring to default configuration, or refreshing the service.
答案 0 :(得分:0)
您应该尝试使用LoginResponseEx
类的KnownType()
属性。
<DataContract(), KnownType(GetType(LoginResponse))>
Public Class LoginResponseEx : Inherits LoginResponse
...
End Class