進程之間的通信,我想作一個簡單的一對一通信兩個長的時間之間運行使用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