在 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。有谁知道我如何弄清楚我的代码(可能在 Class Thing 中)违反了 DataContractSerializer 的限制?