2013-11-27 29 views
5

爲什麼WSDL類型提供者不能消除重載?

#r "FSharp.Data.TypeProviders" 
#r "System.ServiceModel" 

open Microsoft.FSharp.Data.TypeProviders 

[<Literal>] 
let serviceAddress = "http://localhost/Microsoft/Dynamics/GP/eConnect/mex" 

type Dynamics = WsdlService<serviceAddress> 
type DynTypes = Dynamics.ServiceTypes.SimpleDataContextTypes 
type Address = System.ServiceModel.EndpointAddress 

不管我做什麼,WSDL類提供商不能消除歧義函數調用:

let svc: DynTypes.eConnectClient = Dynamics.GeteConnectServiceEndpoint() 
let svc2 = (Dynamics.GeteConnectServiceEndpoint : unit -> DynTypes.eConnectClient)() 
let svc3 = (Dynamics.GeteConnectServiceEndpoint : Address -> DynTypes.eConnectClient)(Address serviceAddress) 

他們沒有工作。

禁用其他終端並僅保留eConnectClient用於解決問題,但我甚至不知道是否可能最終需要其他終端。

+0

我主要想到這可能是WSDL類型提供程序中的錯誤。看起來,如果您有多個具有不同合約的端點,則WSDL類型提供程序會爲您提供針對每個不同端點的所有方法,但會爲每個具有與所有其他端點匹配的不同返回類型的端點提供重載。 –

+0

我可能在這裏是錯誤的,但我認爲即使返回類型不同,C#&F#也會禁止使用相同類型簽名的重載,但這在.NET框架中可能是WSDL類型提供者能夠實現的生成。 –

+0

當我嘗試WSDL類型提供程序時,發現了一堆這樣的問題。 IIRC,它們通常是底層C#代碼生成器的問題,而不是F#和類型提供程序的特定問題。 –

回答

0

不熟悉模式或類型提供程序,但WSDL標準不支持重載。如果WSDL是在運行時從實現中生成的(如往常一樣),那麼運行時可能會產生這樣一個無效的WSDL。

0

我能夠通過使用反射來找到我想要調用的方法並動態調用它,從而解決了這個問題。

let noteServiceType = typedefof<NoteService> 
let creatorMethod = 
    noteServiceType.GetMethods() 
    |> Seq.filter (fun staticMethod -> 
     staticMethod.Name = "GetCustomBinding_IIntakeNoteManager" 
     && staticMethod.ReturnType = typedefof<NoteService.ServiceTypes.SimpleDataContextTypes.IntakeNoteManagerClient> 
     && staticMethod.GetParameters().Length = 0) 
    |> Seq.toList 

let creatorMethod = creatorMethod |> Seq.head 

let client = creatorMethod.Invoke(null, [||]) :?> NoteService.ServiceTypes.SimpleDataContextTypes.IntakeNoteManagerClient 
相關問題