gpt4 book ai didi

WCF 路由——如何以编程方式正确添加过滤表

转载 作者:行者123 更新时间:2023-12-04 16:46:38 27 4
gpt4 key购买 nike

我正在使用 WCF 4 路由服务,并且需要以编程方式配置服务(而不是通过配置)。我见过的这样做的例子很少见,创建一个 MessageFilterTable 如下:

            var filterTable=new MessageFilterTable<IEnumerable<ServiceEndpoint>>();

但是,该方法的通用参数应该是 TFilterData(您要过滤的数据类型)?我有自己的接受字符串的自定义过滤器——我还能用这种方式创建过滤器表吗?

如果这可行...路由基础架构会在我传入的列表之外创建客户端端点吗?

最佳答案

我创建了一个 WCF 4 路由服务并以编程方式对其进行了配置。我的代码比它需要的间隔要大一些(其他人的可维护性是一个问题,因此是评论),但它确实有效。这有两个过滤器:一个将一些特定的操作过滤到给定的端点,第二个将剩余的操作发送到一个通用的端点。

        // Create the message filter table used for routing messages
MessageFilterTable<IEnumerable<ServiceEndpoint>> filterTable = new MessageFilterTable<IEnumerable<ServiceEndpoint>>();

// If we're processing a subscribe or unsubscribe, send to the subscription endpoint
filterTable.Add(
new ActionMessageFilter(
"http://etcetcetc/ISubscription/Subscribe",
"http://etcetcetc/ISubscription/KeepAlive",
"http://etcetcetc/ISubscription/Unsubscribe"),
new List<ServiceEndpoint>()
{
new ServiceEndpoint(
new ContractDescription("ISubscription", "http://etcetcetc/"),
binding,
new EndpointAddress(String.Format("{0}{1}{2}", TCPPrefix, HostName, SubscriptionSuffix)))
},
HighRoutingPriority);

// Otherwise, send all other packets to the routing endpoint
MatchAllMessageFilter filter = new MatchAllMessageFilter();
filterTable.Add(
filter,
new List<ServiceEndpoint>()
{
new ServiceEndpoint(
new ContractDescription("IRouter", "http://etcetcetc/"),
binding,
new EndpointAddress(String.Format("{0}{1}{2}", TCPPrefix, HostName, RouterSuffix)))
},
LowRoutingPriority);

// Then attach the filter table as part of a RoutingBehaviour to the host
_routingHost.Description.Behaviors.Add(
new RoutingBehavior(new RoutingConfiguration(filterTable, false)));

关于WCF 路由——如何以编程方式正确添加过滤表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6118201/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com