在VB.NET(使用Visual Studio 2008)我的WCF服务有一个接口是这样的:入门坏的“更新服务引用”生成的代码
<ServiceContract()> _
Public Interface IThingService
<OperationContract()> _
Function GetThingByNumber(ByVal thingNumber As MyKeyClass) As Thing
<OperationContract()> _
Function GetThing(ByVal thingId As Guid) As Thing
' ...
End Interface
我最近改变了两个项目类似的代码使用basicHttpBinding而不是wsHttpBinding。一切都在服务方面编译好。现在,在客户端应用程序中,我选择“更新服务参考”。在一个项目中,我的结果reference.vb看起来是正确的 - 对于每种方法,在100行下使用简单的包装。但是,另一方面,由此产生的reference.vb似乎无法理解该服务是什么。我得到了1000线,看起来像一个reference.vb:
'------------------------------------------------------------------------------
' <auto-generated>
' This code was generated by a tool.
' Runtime Version:2.0.50727.3053
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict On
Option Explicit On
Imports System.Data
Namespace ThingService
<System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0"), _
System.ServiceModel.ServiceContractAttribute(ConfigurationName:="GetThingByVersion.IGetThingByVersion")> _
Public Interface IThingService
'CODEGEN: Parameter 'GetThingByNumberResult' requires additional schema information that cannot be captured using the parameter mode. The specific attribute is 'System.Xml.Serialization.XmlElementAttribute'.
<System.ServiceModel.OperationContractAttribute(Action:="http://tempuri.org/ThingService/GetThingByVersion", ReplyAction:="http://tempuri.org/ hingService/GetThingByVersionResponse"), _
System.ServiceModel.XmlSerializerFormatAttribute()> _
Function GetThingByNumber(ByVal request As ThingService.GetThingByVersionRequest) As ThingService.GetThingByVersionResponse
'CODEGEN: Parameter 'GetThingResult' requires additional schema information that cannot be captured using the parameter mode. The specific attribute is 'System.Xml.Serialization.XmlElementAttribute'.
<System.ServiceModel.OperationContractAttribute(Action:="http://tempuri.org/ThingService/GetThing", ReplyAction:="http://tempuri.org/ThingService/GetThingResponse"), _
System.ServiceModel.XmlSerializerFormatAttribute()> _
Function GetThing(ByVal request As ThingService.GetThingRequest) As ThingService.GetThingResponse
'...
End Interface
'''<remarks/>
<System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.3082"), _
System.SerializableAttribute(), _
System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute("code"), _
System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://schemas.datacontract.org/2004/07/ThingLibraryCore")> _
Partial Public Class MyKeyClass
Inherits Object
Implements System.ComponentModel.INotifyPropertyChanged
Private concatenatedThingNumberField As String
Private ThingNumberField As Integer
Private ThingNumberFieldSpecified As Boolean
'... goes on and on...
这是因为如果生成的代码,一点也不了解我实际的服务接口。任何想法如何解决这个问题?提前致谢。
编辑:看起来我需要确保服务器可以使用DataContractSerializer而不是XmlSerializer:请参阅http://blogs.msdn.com/sonuarora/archive/2007/06/16/contract-generation-from-wsdl-xml-schema-datacontractserializer-vs-xmlserializer.aspx。有谁知道我怎么能弄清楚什么在我的代码(可能在类事)违反DataContractSerializer的限制?
查看生成的代码中的注释。他们告诉你什么是错的。 – 2009-08-18 14:32:21
我不明白他们。什么是“参数模式”?它应该在哪里获取架构信息? XmlElementAttribute应该告诉我什么?我用google搜索无济于事。 – 2009-08-18 14:40:18
注意,例如,GetThing(Guid)在接口中,但生成的客户端具有GetThing(String)。我也无法确定这一部分。 – 2009-08-18 14:53:31