Solved

.NET Service Client DateTime Time Zone Offset Compatability Issue

Posted on 2011-03-21
2
1,525 Views
Last Modified: 2012-05-11
I'm attempting to communicate with a Java webservice via a .NET application, using a Visual Studio Service reference (System.ServiceModel namespace classes). I've found that whenever it serializes a DateTime value it does not specify the offset. The problem is two fold:

I can't figure out how to create a DateTime object with a specific time zone. I can create a DateTimeOffset that will accomplish this, but the service client is expecting a DateTime object.
When the DateTime object is serialized, it does not include the time zone offset.
To elaborate on issue #2, the XML that the service expects for the timestamp object is as follows:

<startDate>2011-03-18T00:00:00-07:00</startDate>
<endDate>2011-03-19T00:00:00-07:00</endDate>

Open in new window


However, the XML that I see when tracing the .NET app is as follows:

<startDate>2011-03-18T00:00:00</startDate>
<endDate>2011-03-19T00:00:00</endDate>

Open in new window


The web service requires the time zone, because the underlying data is tracked in GMT-0. The data that is returned is in daily intervals, so if I don't specify a time zone then I get data back for GMT-0. Only when I provide the offset in the query do I get the in the data correct time zone.
0
Comment
Question by:Ryan McCauley
2 Comments
 
LVL 10

Expert Comment

by:Chad Smith
ID: 35184214
0
 
LVL 11

Accepted Solution

by:
lenordiste earned 500 total points
ID: 35184519
You could try implementing a custom IClientMessageFormatter to alter the XML you are sending to the java service. This way you can still use a DateTime as forced by the java webservice API and programatically add timezone information on the fly before sending your request.

Here is a good read from a user who had the opposite problem you had (receiving timezone offset):
http://stackoverflow.com/questions/3067650/how-to-ignore-timezone-of-datetime-in-net-wcf-client

please note that he customizes the DeserializeReply method in order to strip timezone offset information while in your case you should work on the SerializeRequest method which he left intact.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now