在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