For parameters to an OperationContract that represent a date only (no time component or timezone designator), it is desirable to use xs:Date, to avoid any ambiguity or probl
You specified a requirement to have xs:Date as a parameter in the operation. The thing is, there's a formal way to specify such requirements: WSDL. If I were doing this I would use a WSDL First approach. Start with a WSDL that defines the contract you want, including an xs:date in the interface, wherever it is you want it. Then generate the service stub using svcutil.exe. Remember to pass in /serializer:xmlSerializer .
WCF's defaut serializer (DataContractSerializer) does not support it. But XmlSerializer supports it.
1 - Add the [XmlSerializerFormat] attribute to your contract...
[XmlSerializerFormat]
[ServiceContract]
public interface IMyContract
{
MyType GetData();
}
2 - In the DataContract type, add the [XmlElement(DataType = "date")] to the member.
public class MyType
{
[XmlElement(DataType = "date")]
public DateTime BirthDate {get; set;}
}
Hope this helps
I've also got described issue. I've developed my own solution - WcfDate custom type. It is published here: WCF Support for xs:date
Now that this has come to my attention, I have created a new Suggestion in Connect, at Please Fully Support xs:Date for Date-Only Parameters and DataMembers. I rated this with four stars (important).
If anyone reading this feels this is important (or else disagrees), then please use Connect to vote on it or comment on it.
Unfortunately WCF doesn't support the xs:Date type. You'd have to create your own "DateOnly" struct, like:
<DataContract()> _
public struct DateOnly
<DataMember()> public Month as Integer
<DataMember()> public Day as Integer
<DataMember()> public Year as Integer
end struct