views:

22

answers:

1

I'm trying to call a web service from .NET 3.5 using WCF. The error I'm getting currently is

An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail.

InnerException: {"Value -2147483648 for millisOfSecond must be in the range [0,999]"}

I've narrowed it down to two date values I'm sending. When I create the request through soapUI, and send the date values in this format:

2010-07-19T00:00:00.000Z

everything works fine, but when I call the service from .NET, it sends the dates in this format

2010-07-19T00:00:00

and it results in the error above. If I send the incorrect date in soapUI, I get the same error message. Note that these dates are required fields, so if I send nothing it puts a default date of 0001-01-01T00:00:00 in, which is still obviously in the wrong format.

How can I control how the date is sent to the web service?

+1  A: 

Not sure if there's an easier way for this (haven't found it, yet, if it exists) - but one method of doing this would be to introduce a string field that properly formats your date, and then avoid serializing the date field directly, but instead serialize the formatted string:

public partial class YourDataClass
{

    public DateTime YourDate { get; set; }

    [DataMember(Name="YourDate")]
    public string FormattedDate
    {
        get { return string.Format("{0:yyyy-MM-ddTHH:mm:ss.fffZ}", YourDate);
        set { ; }
    }
}

With this, the DateTime field YourDate won't be serialized (no [DataMember] attribute on it - assuming you're using the DataContract serializer in WCF), while the formatted date string will be serialized as YourDate in the proper format.

marc_s