2016-01-28 67 views
0

當我在對象中包含datetime屬性並在wcf服務中返回它時,它會給出錯誤狀態12152.沒有我的對象中的日期時間屬性它工作正常。日期時間屬性內容是#1/22/2016 12:08:36 PM#。 如何使它與datetime屬性一起使用?序列化datetime屬性時出錯

WCF調用

function populateEditAuditResultData(AuditID) { 
     CallWCFService('DataService.svc/GetAuditCase', 
     '{"AuditID": "' + AuditID + '"}', 
     function (result) { //success 

     }, 
     function (jQXHR, textStatus, errorThrown) { //failure 

     } 
    ); 
} 

WCF服務

<OperationContract()> _ 
Public Function GetAuditCase(ByVal AuditID As Integer) As AuditCase 
    Return New AuditCase(AuditID) 
End Function 

構造

Public Sub New(ByVal AuditID As String) 
    Me.AuditID = AuditID 
    Me.GetData() 
End Sub 
Public Sub GetData() 
    Dim conn = New DatabaseConnection() 
    Dim params = New List(Of SqlParameter) 
    If AuditID <> Nothing Then params.Add(New SqlParameter("AuditID", Me.AuditID)) 
    Dim table = conn.RunSprocQuery(ReferenceData.prc_GetAuditCaseDetails, params.ToArray()) 
    If table.Rows.Count > 0 Then 
     ReadAuditCase(table.Rows(0), Me) 
    End If 
End Sub 

Private Shared Sub ReadAuditCase(ByVal row As DataRow, ByRef AudCase As AuditCase, Optional ByVal IncludeOptionalFields As Boolean = True) 
    AudCase.AuditID = CInt(row("AuditID")) 
    AudCase.AuditTypeID = CInt(row("AuditTypeID")) 
    AudCase.AllocationOn = Convert.ToDateTime(row("AllocationOn")) 
End Sub 
+0

**顯示您的代碼。** ** –

+0

已添加代碼。請查閱。 –

回答

0

好的改變時區UTC解決了這個問題。 另外,它可以通過使用下面的代碼來解決。

AudCase.AllocationOn = Convert.ToDateTime(row("AllocationOn")).ToUniversalTime() 

希望這可以幫助別人。