You can specify names on F# interfaces, so here's the version that gets rid of the need for MessageContract:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
open System.Runtime.Serialization
open System.ServiceModel

module Namespace =
    [<Literal>]
    let Mine = "urn:mine:myservice"

[<DataContract(Namespace = Namespace.Mine)>]
type MyMethodRequest() =
    let mutable parameter1 = 0
    let mutable parameter2 = 0m
    [<DataMember>]
    member r.Parameter1 with get() = parameter1 and set(p1) = parameter1 <- p1
    [<DataMember>]
    member r.Parameter2 with get() = parameter2 and set(p2) = parameter2 <- p2

[<DataContract(Namespace = Namespace.Mine)>]
type MyMethodResult() =
    let mutable parameter3 = 0m
    [<DataMember>]
    member r.Parameter3 with get() = parameter3 and set(p) = parameter3 <- p

[<ServiceContract(Namespace = Namespace.Mine)>]
type IMyService =
    [<OperationContract>]
    abstract MyMethod: req:MyMethodRequest -> MyMethodResult

[<ServiceBehavior(Namespace = Namespace.Mine)>]
type MyService() =
    interface IMyService with
        member l.MyMethod (request:MyMethodRequest) =
            new MyMethodResult(Parameter3 = 100m)

I'm not sure offhand about the DataContract issue.

By on 10/3/2008 1:21 PM ()

Thanks! That was easier than I thought. I think the immutable object thing is harder. I was thinking that maybe something is possible with the IDataContractSurrogate but I haven't looked into it and in any I don't expect the code to become smaller.

By on 10/3/2008 2:48 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper