0

I have a WCF service receiving data from a client. The data in the client has a time stamp in it. As part of some troubleshooting, I used the WCF Trace tools and noticed that the time stamp saved on the client side is serialized with the client time offset in it, but when the message is received on the server, the time offset shows up with the server time offset. Example:

  • Client is GMT-2
  • Server is GMT-7
  • Trace log on the client has a field in the message that says: 2021-12-02T20:24:10.1234567-02:00
  • Trace log on the server has that message but the timeStamp listed as: 2021-12-02T20:24:10.1234567-07:00

I found this very strange and tried to dig deeper. My hypothesis was that during deserialization WCF may have automatically converted it, but I would assume that the raw message if printed out as string would have the "-02:00" in it. So I implemented a message filter and output the message using:

public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
{
   _logger.Information($"message: {request.ToString()}");
   ...
}

Running this, my logged message however still shows a converted rather than original time stamp. My next hypothesis was that the Message.ToString method was deserializing it with whatever default deserializer we have. So I tried to use an XMLSerializer to parse just the timestamp out myself:

public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
{
   var bufferedMessage = request.CreateBufferedCopy(int.MaxValue);
   var message = bufferedMessage.CreateMessage();
   var xmlOutput = "";
   var xmlReader = message.GetReaderAtBodyContents();
   while (xmlReader.Read())
   {
      if (xmlReader.Name == "timeStamp")
      {
         xmlReader.Read();
         _logger.Information($"Raw Timestamp: {xmlReader.Value}");
      }
   }
   _logger.Information($"message :\r\n{xmlOutput}");

   request = bufferedMessage.CreateMessage();
   return null;
}

Yet I still get the timestamp returned in the server time zone. This now leaves me out of ideas on what to try next because:

  • WCF Trace logs on client show that it definitely is putting in the "-2:00" client time zone in there.
  • MessageInspector logging on the server side shows that it is already converted to "-7:00" server time zone.
  • The server has no other endpoint behaviors configured (I checked the configuration file as well as the program itself)
  • The client configuration does not have any other endpoint behaviors configured
  • I have tried changing the ServiceOperation parameter type to string but get the same result (server timestamp shows up)

Anyone have any ideas on what's going on here or where I should probably check next?

  • Try using DateTimeOffset objects - the timezone offset is stored as well and if the time is translated you should be able to translate it back. https://stackoverflow.com/questions/6046277/time-zone-mess-using-wcf – Lan Huang Dec 07 '21 at 05:19
  • I would love to be able to do that but I don't have control over the client code. I can only monitor what it is sending. I tried to phrase the question to figure out what exactly could be happening here with the time offset shown on the client/server side. – Siam Chowdhury Dec 07 '21 at 16:24
  • The server timezone offset is the difference between client local time and server time. Put another way, client local time is the server time plus the server timezone.You can read these articles to help you understand.https://wiki.filezilla-project.org/Server_time_offset &&https://stackoverflow.com/questions/44889018/showing-local-time-based-on-client-server-offset-in-java/44889119 && https://pretagteam.com/question/server-time-instead-of-client-time-javascript – Lan Huang Dec 08 '21 at 07:31

0 Answers0