2011-09-30 53 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ø