Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Consuming Java Webservice with Date and Time elements in WCF

Tags:

c#

wcf

wcf-client

I need to consume a Java Webservice which has elements of type Date and Time.

Example from the wsdl:

...
<xsd:element name="fromTime" nillable="true" type="xsd:time" />
<xsd:element name="dateOfInspection" type="xsd:date" />
...

When consuming the Webservice via Add Service Reference Visual Studio 2008 generates the following code:

[System.Xml.Serialization.SoapElementAttribute(DataType="time", IsNullable=true)]
public System.Nullable<System.DateTime> fromTime { ... }

[System.Xml.Serialization.SoapElementAttribute(DataType="date")]
public System.DateTime dateOfInspection { ... }

Sending a Message results in an reflection error with the innerException:

'time' is an invalid value for the SoapElementAttribute.DataType property. The property may only be specified for primitive types.

When removing the DataType="time" and DataType="date" attributes everything seems to work. But modifying generated code is an anti pattern. So is there any other way to get this working?

Update:

The Problem only exist if the date or time elements are nullable!

I Reported a bug on Microsofts connect site. If you have the same problem you can vote it up here: https://connect.microsoft.com/VisualStudio/feedback/details/534453/consuming-java-webservice-with-nullable-date-and-time-elements-in-wcf-generates-invalid-datatype-attributes

Update 2:

Microsoft confirmed it's a bug and unlikly to be fixed.

Update 3:

I Checked with VS2010 and it still generates the wrong code. Btw, we ended up modifying the generated code...

like image 746
Thomas Avatar asked Feb 17 '10 09:02

Thomas


1 Answers

A potential workaround for the bug would be to create your own proxy generator. This is similar to modifying the generated code, but is arguably better because you're changing what is generated, rather than doing a post-generation modification.

See http://blogs.msdn.com/b/pedram/archive/2007/08/10/customising-wcf-proxy-generation-in-visual-studio-2008.aspx for instructions. Notes regarding the path of the registry entries you need to create: VS2010 will have 10.0 as the version in the registry path, and on 64-bit Windows it needs to be in SOFTWARE\Wow6432Node\Microsoft, not SOFTWARE\Microsoft.

I'm not sure which generators this is and isn't possible/easy for, except that you can do it with the WcfProxyGenerator by extending the class used by that tool (that's what's done in the above link).

like image 111
Tim S. Avatar answered Oct 27 '22 04:10

Tim S.