I am using this template to create a web service.
Here is a Web Service Contract I am using:
[<ServiceContract>]
type ISimpleService =
[<OperationContract>]
abstract GetItems: value:int -> Item[]
[<OperationContract>]
abstract InsertItem: composite:Item -> int
value
and composite
description? Is it language feature or something else?The value
and composite
symbols in the code sample are just names of the parameters. This pretty much corresponds to the following C# interface:
[ServiceContract]
interface ISimpleService {
[OperationContract]
Item[] GetItems(int value);
[OperationContract]
int InsertItem(Item composite);
}
If you want to change the definition so that InsertItem
does not return anything and GetItem
does not take anything, you need to change their return and input types to unit
:
[<ServiceContract>]
type ISimpleService =
[<OperationContract>]
abstract GetItems: unit -> Item[]
[<OperationContract>]
abstract InsertItem: composite:Item -> unit
The unit
type (roughly) corresponds to void
in C# when used as a return type and this is also how it will be compiled. When used as input, unit
corresponds to an empty parameter list (and it is compiled as such).
This may sound confusing, but the unit
type is an F# type with just one value written as ()
, so when you call foo()
, you are actually passing the value of type unit
as an argument. This takes some time getting used to, but it makes the language elegantly simple.