Solved

.NET Service Client DateTime Time Zone Offset Compatability Issue

Posted on 2011-03-21
2
1,551 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB .NET application would like equitable cpu usage 3 25
Getfiles in vb.net 28 44
How do ASP.NET and MVC work together? 4 30
Advice on Xojo as a development tool over VB. 4 40
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Here I am going to explain creating proxies at runtime for WCF Service. So basically we use to generate proxies using Add Service Reference and then giving the Url of the WCF service then generate proxy files at client side. Ok, what if something ge…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

861 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

25 Experts available now in Live!

Get 1:1 Help Now