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
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)
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ø
精彩评论