我在工作 MEX 服务于:
net.tcp://remotehost:4508
什么是最短的 C#/F# 代码(很难理解 XML 配置文件 ^_^"),我可以编写它来创建一个路由器?:
net.tcp://localhost:4508
MEX 也应该正确路由,以便客户端可以使用路由器
svcutil net.tcp://localhost:4508
发现服务方法。
最佳答案
这是我对我的问题的回答,它完全符合我的要求——没有任何 XML 沙拉,在不到 50 行的 F# 中:
namespace CORSIS
module Application =
open System
open System.ServiceModel
open System.ServiceModel.Routing
open System.ServiceModel.Dispatcher
open System.ServiceModel.Description
let createSimpleRouter createBinding (routerAddress : string) serviceAddress =
let routerType = typeof<IRequestReplyRouter>
let routerContract = ContractDescription.GetContract(routerType)
let endpoint address = new ServiceEndpoint(routerContract, createBinding(), new EndpointAddress(address))
let serviceEndpoints = [| endpoint serviceAddress |]
let configuration = new RoutingConfiguration()
configuration.FilterTable.Add(new MatchAllMessageFilter(), serviceEndpoints)
let host = new ServiceHost(typeof<RoutingService>)
ignore <| host.AddServiceEndpoint(routerType, createBinding(), routerAddress)
host.Description.Behaviors.Add(new RoutingBehavior(configuration))
host
[<EntryPoint>]
let main(args) =
let (routerAddress, serviceAddress) =
match args with
| [| ra; sa |] -> (ra, sa)
| _ -> ("net.tcp://localhost:4508/", "net.tcp://remotehost:4508/")
let netTcp() = new NetTcpBinding(SecurityMode.None)
let mexTcp() = MetadataExchangeBindings.CreateMexTcpBinding()
let tcpRouter = createSimpleRouter netTcp routerAddress serviceAddress
let mexRouter = createSimpleRouter mexTcp (routerAddress + "mex") (serviceAddress + "mex")
tcpRouter.Open()
mexRouter.Open()
Console.WriteLine("routing ...\n{0} <-> R:{1}", serviceAddress, routerAddress)
ignore <| Console.ReadKey true
0
关于c# - WCF 4.0 路由与 mex 使用 System.ServiceModel.Routing.RoutingService,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5214858/