简体   繁体   中英

Exception deserializing DateTime as parameter on WCF SOAP Service C#

After developing a system with two WCF Services on local environment and testing it on another environment, we finally deployed it to a production environment but a totally different error was shown. The two services are running on four different machines (Each service runs on two machines with load balancing).

The operation InvokeEventWithParameters is not working:

[ServiceContract]
public interface IAccountManager
{
    [OperationContract]
    int InvokeEventWithParameters(string EventName, DateTime InitialDate, DateTime FinalDate, int InitialId, int FinalId, string Username);

    [OperationContract]
    int InvokeEvent(string EventName, string Username);
}

When trying to run the services, the following error is returned:

The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'InvokeEventWithParameters'. The value '1/1/2014 12:00:00 AM' cannot be parsed as the type 'DateTime'.

The error is shown on the communication between the two services, on the SOAP message. I can't check if the ISO 8601 is being sent between the services because it is being run on the production environment. I've checked on the testing environment using a sniffer and the ISO is being respected.

What is interesting is the format of the date presented on the error, which is 'en-US', while the system and the IIS are configured as 'pt-BR' and it should be formatted on the ISO standard.

I have already tried to change the machine culture configuration, the IIS globalization configuration and the culture on the web.config files. None of these worked. I've checked the entire project for ".ToStrings" and ".Parses" on datetimes and didn't find none of them, so there is no other possible source of exception.

In my perception, DateTime serialization and deserialization on SOAP messages (Using DataContractDeserializer) shouldn't be affected by any configurations regarding culture, but all I've found on google and here was related to those kinds of settings. Am I right on this assumption?

Thank you for the help, Emilio

I guest it's a service side error, it's waiting for a datetime format but its getting another one. Can you change that's code? if so try parsing received date to a valid format:

DateTime.ParseExact(yourDateParam, "M/d/yyyy hh:mm:ss t", new CultureInfo("en-US"));

pay attention to M/d cuz I don't know if you are sending Month (M) before Day (d) or viceversa.

Happy coding!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM