简体   繁体   中英

WebService type confusion

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
  1. Where can I find value and composite description? Is it language feature or something else?
  2. I want to GetItem method doesn't have any imput parameters and InsertItem doesn't return the value (void). Is it possible?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM