进程之间的通信,我想作一个简单的一对一通信两个长的时间之间运行使用F#F#的过程。他们会定期交换信息。 5秒。到目前为止,我已经达到了这一点:使用WCF和F#
#r "System.ServiceModel"
#r "System.Runtime.Serialization"
//#r @"d:\DLL\Protobuf\protobuf-net.dll"
#time "on"
open System.ServiceModel
[<ServiceContract>]
type IService =
[<OperationContract>]
// [<ProtoBuf.ServiceModel.ProtoBehavior>]
abstract Test: float [] [] [] -> string
type Service() =
interface IService with
member o.Test data = sprintf "Hello, %A" data
let server = System.Threading.Thread (fun() ->
let svh = new ServiceHost (typeof<Service>)
svh.AddServiceEndpoint (typeof<IService>, NetNamedPipeBinding(), "net.pipe://localhost/123") |> ignore
svh.Open())
server.IsBackground <- true
server.Start()
let scf: IService = ChannelFactory.CreateChannel (NetNamedPipeBinding(), EndpointAddress "net.pipe://localhost/123")
let rnd = System.Random()
let arr =
Array.init 100 (fun i ->
Array.init 10 (fun j ->
Array.init 10 (fun k ->
rnd.NextDouble()
)))
printfn "%s" (scf.Test arr)
我收到了很多不同的例外,主要是由于不同的WCF安全限制。
我的问题是
- 我需要什么,以最小的做,使其工作?
- 难道我写的代码正确地使通信尽可能地快?
- 我曾尝试包括protobuf的串行器(见ProtoBehavior代码)进行序列化甚至更快。我是否正确实施了它?我怎么知道WCF实际使用它?
尼斯一个哥们!!! – Nikos