F# 交互式与 F# 解决方案和 WCF

发布于 2024-12-07 06:25:46 字数 995 浏览 0 评论 0原文

尝试在 F# 交互式中运行它:

#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>)

并运行它。我收到以下错误:

组成服务契约的操作中使用的所有参数名称都不能为空。参数名称:名称

有什么问题吗?

PS:我使用 Visual Studio 2010 Ultimate SP1

编辑:只是为了确保 C# 等效项工作正常

Try to run this in 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>)

You will probably succeed. Try to make a new solution.

Reference:

  • System.Runtime.Serialization
  • System.ServiceModel

Paste the following code into 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>)

And run it. I get the following error:

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

What is wrong?

PS: I use Visual Studio 2010 Ultimate SP1

EDIT: just to make sure, the C# equivalent works fine

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

献世佛 2024-12-14 06:25:46

问题确实是您需要为 WCF-Operations 中的参数命名。

这是一个在其中获取命名参数的解决方案(将其命名为a,就像您所做的那样)-至于为什么它在 F#-Interactive 中工作?没有线索,也许它在那里放了一些参数的标准名称。
语法有点奇怪,但您可以在 F# 中定义参数的名称,请尝试:

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

注意:我不知道您是否需要其中的 member 但我刚刚检查了一些文件并确实将它在那里。我在 ATM 周围没有编译器,所以我会把它放在那里,以防万一你真的需要它(但我不这么认为)

The problem is indeed that you need to have names for the parameters in WCF-Operations.

Here is a solution to get named parameters in there (named it a just like you did) - as to why it is working in F#-Interactive? No clue, maybe it puts some standardnames for parameters in there.
The syntax is slightly strange but you can define names for the parameters in F#, try:

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

NOTE: I don't know if you need the member in there but I just checked some of my files and did put it in there. I have no compiler around ATM so I will let it sit there in case you really need it (but I don't think so)

策马西风 2024-12-14 06:25:46

我知道这个问题已被标记为已解答,但我遇到了相同的异常消息,原因完全不同。我只是发帖以防其他人因与我相同的原因遇到相同的问题。

就我而言,除了 -file 和 -targetfile 之外,我还使用 dotNET_Reactor 使用标志“-exclude_types 1 -necrobit 1 -mapping_file 1”来混淆我的 service.exe。

我还没有找到它不起作用的实际“原因”,但消除混淆有帮助。知道 Visual Studio 中的一切都可以正常工作,但在同一台计算机上安装应用程序(被构建服务器混淆)在启动服务时失败,这真是令人沮丧。

比约纳尔·松兹伯

I know this issue has been marked as answered, but I came across the same exception message, for a completely different reason. I just post in case someone else experience the same problem with the same cause I had.

In my case, I used dotNET_Reactor to obfuscate my service.exe with the flags '-exclude_types 1 -necrobit 1 -mapping_file 1' in addition to -file and -targetfile.

I haven't tracked down the actual "why" it didn't work, but removing the obfuscation helped. It was quite frustrating knowing everything worked from visual studio, but installing the application (which was obfuscated by the build server) on the same machine failed when starting the service.

Bjørnar Sundsbø

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文