2011-09-30 40 views
6

嘗試在F#交互運行此:F#互動對F#的解決方案和WCF

#r "System.ServiceModel" 
#r "System.Runtime.Serialization" 

open System.ServiceModel 

[<ServiceContract>] 
type IWCF = 
    [<OperationContract>] 
    abstract Ping: float -> unit 

type WCF() = 
    interface IWCF with 
    member o.Ping a = printfn "Hello, %g" a 

let svh = new ServiceHost (typeof<WCF>) 

你可能會成功。嘗試制定新的解決方案。

參考:

  • System.Runtime.Serialization
  • System.ServiceModel

下面的代碼粘貼到Program.fs

open System.ServiceModel 

[<ServiceContract>] 
type IWCF = 
    [<OperationContract>] 
    abstract Ping: float -> unit 

type WCF() = 
    interface IWCF with 
    member o.Ping a = printfn "Hello, %g" a 

let svh = new ServiceHost (typeof<WCF>) 

並運行它。我收到以下錯誤:

All parameter names used in operations that make up a service contract must not be null. Parameter name: name

出了什麼問題?

PS:我使用Visual Studio 2010旗艦版SP1

編輯:只是爲了確保,在C#相當於正常工作

+0

你有沒有加倍檢查以確定你的目標是.NET運行時的正確版本?我記得,在VS 2010中,F#控制檯應用程序的默認值是.NET 4客戶端配置文件,它不是*完整的.NET配置文件,有時會導致這種「它在此工作但不存在」類型的的問題。 – pblasucci

回答

7

的問題確實是你需要有對WCF的操作參數名稱。

下面是一個解決方案,在那裏獲取命名參數(與您一樣命名爲a) - 至於它爲什麼在F#中工作 - 交互?沒有線索,也許它會爲參數放置一些標準名稱。 語法有點怪,但你可以定義在F#中的參數名稱,請嘗試:

[<ServiceContract>] 
type IWCF = 
    [<OperationContract>] 
    abstract member Ping: a:float -> unit 

注:我不知道,如果你有需要的member但我只是檢查我的一些文件,做了把它放在那裏。我沒有編譯器附近的ATM,所以我會讓它坐在那裏,如果你真的需要它(但我不這麼認爲)

+2

「成員」不是必需的。 – jhamm

+0

謝謝,這有幫助!我不知道接口成員的參數也可以有名稱。 –

1

我知道這個問題已被標記爲已回答,但我遇到了相同的異常消息,完全不同的原因。我只是發帖,以防其他人遇到同樣的問題,我有同樣的原因。

在我的情況,我用dotNET_Reactor混淆我service.exe與標誌除了-file和-targetfile '-exclude_types 1 -necrobit 1 -mapping_file 1'。

我沒有跟蹤實際的「爲什麼」它沒有工作,但刪除混淆幫助。知道從Visual Studio工作的所有東西都很令人沮喪,但在啓動服務時,在同一臺計算機上安裝應用程序(由生成服務器模糊處理)失敗。

BjørnarSundsbø