Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate xs:Date in WCF OperationContract parameter

Tags:

.net

xml

wcf

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 problems with timezone conversion between client and server.

WCF currently only supports xs:DateTime for serializing DateTime parameters.

What is the easiest way to generate an OperationContract with a parameter that will be serialized as xs:Date?

I'm thinking of having a custom .NET Type "public struct DateOnly" or similar, with implicit casting to/from a standard DateTime, that will somehow automatically generate wsdl as xs:Date.

Is this possible, and how would I go about implementing it?

If it is possible, I suspect the solution might involve using XmlSchemaProviderAttribute on the custom type, but any documentation I've found on this attribute seems a bit opaque.

Update

I find it difficult to believe it will increase the probablity of getting a solution, but I'll follow the site's advice and start a bounty.

For clarity's sake, the condition for the bounty is to provide all the information necessary to construct a solution so that a parameter to a WCF OperationContract can be:

  • serialized as ws:Date and described as such in the generated WSDL.

  • is either a System.DateTime value or can be cast implicitly to/from DateTime.

like image 796
Joe Avatar asked Apr 22 '09 10:04

Joe


3 Answers

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.

like image 138
John Saunders Avatar answered Nov 10 '22 17:11

John Saunders


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 .

like image 3
Cheeso Avatar answered Nov 10 '22 15:11

Cheeso


I've also got described issue. I've developed my own solution - WcfDate custom type. It is published here: WCF Support for xs:date

like image 3
robsosno Avatar answered Nov 10 '22 15:11

robsosno