尝试在F#interactive中运行它:
#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>)
Run Code Online (Sandbox Code Playgroud)
你可能会成功.尝试制作新的解决方案.
参考:
将以下代码粘贴到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>)
Run Code Online (Sandbox Code Playgroud)
并运行它.我收到以下错误:
构成服务合同的操作中使用的所有参数名称都不能为空.参数名称:名称
怎么了?
PS:我使用的是Visual Studio 2010 Ultimate SP1
编辑:只是为了确保,C#等效工作正常
问题确实是你需要为WCF-Operations中的参数命名.
这里有一个获得命名参数的解决方案(a
就像你一样命名) - 为什么它在F#中工作--Interactive?没有任何线索,也许它为那里的参数设置了一些标准名称.语法有点奇怪但您可以在F#中定义参数的名称,请尝试:
[<ServiceContract>]
type IWCF =
[<OperationContract>]
abstract member Ping: a:float -> unit
Run Code Online (Sandbox Code Playgroud)
注意:我不知道你是否需要member
在那里,但我只是检查了我的一些文件,并确实把它放在那里.我没有ATM周围的编译器所以我会让它坐在那里以防你真的需要它(但我不这么认为)