2015-08-19 22 views
3

我來自智利是和時區當前設置爲GMT -3:00。我的平臺配置了這些時區設置:日期時間從SOAP的WebLogic服務轉變爲WCF應用

Oracle數據庫:GMT -3:00

的WebLogic服務器:GMT -3:00

Windows 7客戶端:GMT -3:00

第一次查詢:日期= 26

執行此查詢時,我得到了奇怪的結果/ 03/08 06:10:00,000000000

第二查詢:日期= 24/05/13 18:48:00,000000000

我可以看到(通過SOAP UI)在WebLogic返回此結果:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> 
    <S:Body> 
     <ns2:fobpgGestacionesPorFichaResponse xmlns:ns2="http://nucleo.alemana.cl/"> 
     <fobpgGestacionesPorFichaResult> 
      <gestaciones> 
       <controles>7</controles> 
       <esGestaTerminada>1</esGestaTerminada> 
       <fechaPrimerControl>2007-10-05T00:00:00-03:00</fechaPrimerControl> 
       <fechaTermino>2008-03-26T06:10:00-03:00</fechaTermino> 
       ..............^ date #1 is here 

       <fur>2007-08-05T00:00:00-03:00</fur> 
       <furOp>2007-08-05T00:00:00-03:00</furOp> 
       <gesdaFechaCreacion>2015-08-19T14:58:41.903-03:00</gesdaFechaCreacion> 
       <gesnuIdGesta>45087</gesnuIdGesta> 
       <gesnuNroGesta>1</gesnuNroGesta> 
       <rnMayorPeso>0</rnMayorPeso> 
      </gestaciones> 
      <gestaciones> 
       <controles>12</controles> 
       <esGestaTerminada>1</esGestaTerminada> 
       <fechaPrimerControl>2012-10-11T00:00:00-03:00</fechaPrimerControl> 
       <fechaTermino>2013-05-24T18:48:00-03:00</fechaTermino> 
       ..............^ date #2 is here 

       <fur>2012-08-27T00:00:00-03:00</fur> 
       <furOp>2012-08-27T00:00:00-03:00</furOp> 
       <gesdaFechaCreacion>2015-08-19T14:58:28.071-03:00</gesdaFechaCreacion> 
       <gesnuIdGesta>45086</gesnuIdGesta> 
       <gesnuNroGesta>2</gesnuNroGesta> 
       <rnMayorPeso>1980</rnMayorPeso> 
      </gestaciones> 
     </fobpgGestacionesPorFichaResult> 
     </ns2:fobpgGestacionesPorFichaResponse> 
    </S:Body> 
</S:Envelope> 

然而,當我的客戶WPF應用程序連接到WebLogic服務,並獲取上述數據,我得到這些值(在調試模式):

1日起反應

1st date response

這是什麼,我期望(6:10)提前一小時(7:10)。

第二日響應

2nd date response

這是預期(18:48)!

我不知道是怎麼回事。爲什麼這些結果不一致?

+0

嗨F.Rojas,我編輯你的問題,清理語法和格式。如果您覺得我改變了問題的含義,請隨時回滾。歡迎來到堆棧溢出! –

+0

SOAP響應看起來正確。你可以反序列化爲'DateTimeOffset'而不是'DateTime'並檢查它認爲它有哪些時區數據? –

+0

我在ServiceReference setter中更改了System.DateTime對於System.DateTimeOffset。所有日期的返回數據如下: 01-01-0001 0:00:00 +00:00 –

回答

0

我已經收到這個問題,它真的使我迷惑不解。 .NET將連載/基於機器的時區配置反序列化XML時,自動更改DateTime值。這是.NET試圖有幫助,但不是一個預期的行爲,因此往往會造成很多混亂。

在任何應用程序來處理DateTime最好的辦法是存儲UTC日期時間,然後在客戶端上的本地格式顯示出來。

但是,更快的修復,不涉及所有的日期時間轉換爲UTC會是這樣:

試着改變你的DateTime這麼說DateTimeKind是不確定的,XML序列化器不會嘗試將它們轉換。例如,該代碼將一個日期轉換爲DateTimeKind.Unspecified

DateTime newDate = DateTime.SpecifyKind(oldDate, DateTimeKind.Unspecified); 

你可以看到這Coding Best Practices Using DateTime in the .NET Framework微軟長期指導獲取更多信息。

相關問題