简体   繁体   English

在WCF中使用带有Date和Time元素的Java Webservice

[英]Consuming Java Webservice with Date and Time elements in WCF

I need to consume a Java Webservice which has elements of type Date and Time. 我需要使用具有Date和Time类型元素的Java Webservice。

Example from the wsdl: 来自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: 通过添加服务引用消费Web服务时Visual Studio 2008生成以下代码:

[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: 使用innerException发送消息会导致反射错误:

'time' is an invalid value for the SoapElementAttribute.DataType property. 'time'是SoapElementAttribute.DataType属性的无效值。 The property may only be specified for primitive types. 只能为基本类型指定该属性。

When removing the DataType="time" and DataType="date" attributes everything seems to work. 删除DataType =“time”和DataType =“date”属性时,一切似乎都有效。 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 如果您遇到同样的问题,可以在这里投票: https//connect.microsoft.com/VisualStudio/feedback/details/534453/consuming-java-webservice-with-nullable-date-and-time-elements-in -wcf-生成-无效-数据类型的属性

Update 2: 更新2:

Microsoft confirmed it's a bug and unlikly to be fixed. 微软证实这是一个错误,并且不太理解。

Update 3: 更新3:

I Checked with VS2010 and it still generates the wrong code. 我检查VS2010,它仍然生成错误的代码。 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. 有关说明,请参见http://blogs.msdn.com/b/pedram/archive/2007/08/10/customising-wcf-proxy-generation-in-visual-studio-2008.aspx 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 . 有关您需要创建的注册表项的路径的注释:VS2010将在注册表路径中具有10.0作为版本,而在64位Windows上,它需要位于SOFTWARE\\Wow6432Node\\Microsoft ,而不是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). 我不确定这是哪个生成器,并且不可能/不容易,除了你可以通过扩展该工具使用的类来完成WcfProxyGenerator(这是在上面的链接中完成的)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM