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...
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With