[Web Service]Apache axis 1.4 timezone bug
https://issues.apache.org/jira/browse/AXIS-2673
服務程式 -
1: public Calendar helloDateTime(Calendar d){
2: return d;
3: }
WSDL
1: <element name="helloDateTime">
2: <complexType>
3: <sequence>
4: <element name="d" type="xsd:dateTime"/>
5: </sequence>
6: </complexType>
7: </element>
8: <element name="helloDateTimeResponse">
9: <complexType>
10: <sequence>
11: <element name="helloDateTimeReturn" type="xsd:dateTime"/>
12: </sequence>
13: </complexType>
14: </element>
回傳值晚了8個小時 ?!
雖然 apache 沒有正式將 axis 中止, 但已經很久沒有更新了, Bug 似乎也沒有去解,
資源應該都轉往 axis2 了, 但IT人總是得為這種債務做處理.
Java Service 解法:
http://stackoverflow.com/questions/5615672/how-to-pass-java-date-to-net-webservice-using-axis
1: public Calendar helloDateTime(Calendar d){
2: d.set(Calendar.DST_OFFSET, 0); //Clear the daylight savings offset
3: d.set(Calendar.ZONE_OFFSET, 0); //Clear the timezone offset
4: return d;
5: }
.NET Client 解法:
DateTime td = new DateTimeOffset(
d.Year,d.Month,d.Day,
d.Hour,d.Minute,d.Second,d.Millisecond,
new System.Globalization.CultureInfo("en-US").Calendar,
TimeSpan.Zero).DateTime;
用 Fiddler 可以看到時間後面的 Time zone 的 OFFSET 不會出現了.
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<helloDateTime xmlns="http://ws.datetime.com">
<d>2012-09-29T02:33:18.147</d>
</helloDateTime>
</soap:Body>
</soap:Envelope>
其它參考資料: