我在以下位置为MEX工作提供服务:
net.tcp://remotehost:4508
我可以写出最短的C#/ F#代码(很难理解XML配置文件^ _ ^“)是什么?
net.tcp://localhost:4508
MEX还应该正确路由,以便客户端可以使用路由器
svcutil net.tcp://localhost:4508
发现服务方法。
最佳答案
这是我对我的问题的回答,正是我想要的—在不到50行的F#中没有任何XML沙拉:
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# - 使用System.ServiceModel.Routing.RoutingService与mex进行WCF 4.0路由,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5214858/