WCF路由——如何以编程方式正确添加过滤表
我正在使用 WCF 4 路由服务,并且需要以编程方式配置该服务(而不是通过配置)。我见过的这样做的例子很少见,创建一个 MessageFilterTable 如下:
var filterTable=new MessageFilterTable<IEnumerable<ServiceEndpoint>>();
但是,该方法的通用参数应该是 TFilterData (您要过滤的数据类型)?我有自己的接受字符串的自定义过滤器 - 我仍然可以通过这种方式创建过滤器表吗?
如果这可行...路由基础设施是否会从我传入的列表中创建客户端端点?
I am using the WCF 4 routing service, and need to configure the service programmatically (as opposed to via config). The examples I have seen of doing so, which are rare, create a MessageFilterTable as follows:
var filterTable=new MessageFilterTable<IEnumerable<ServiceEndpoint>>();
But, the generic parameter to that method is supposed to be TFilterData (the type of data you are filtering on)? I have my own custom filter that accepts a string -- can I still create the filter table this way?
If this will work...will the routing infrastructure create client endpoints out of the list I pass in?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我创建了一个 WCF 4 路由服务并以编程方式配置它。我的代码比它需要的间隔要大一些(其他人的可维护性是一个问题,因此有评论),但它确实有效。它有两个过滤器:第一个过滤到给定端点的一些特定操作,第二个将其余操作发送到通用端点。
I have created a WCF 4 routing service and configured it programmatically. My code is a bit more spaced out than it needs to be (maintainability for others being a concern, hence the comments), but it definitely works. This has two filters: one filters some specific Actions to a given endpoint, and the second sends the remaining actions to a generic endpoint.
您可以在 MSDN 上找到一个很好的示例:如何:动态更新路由表
请注意,他们不直接创建 MessageFilterTable 的实例,而是使用新 RoutingConfiguration 实例提供的“FilterTable”属性。
如果您编写了自定义过滤器,那么您将像这样添加它:
CustomMessageFilter 将是您的过滤器,“customStringParameter”是(我相信)您正在谈论的字符串。
当路由器收到连接请求时,它将尝试通过此表条目映射它,如果成功,那么您是对的,路由器将创建一个客户端端点来与您提供的 ServiceEndpoint 进行通信。
You can find a good example on MSDN here: How To: Dynamic Update Routing Table
Note how they dont directly create an instance of the MessageFilterTable, but instead use the 'FilterTable' property provided by a new RoutingConfiguration instance.
If you have written a custom filter, then you will add it like this:
The CustomMessageFilter will be your filter, and the "customStringParameter" is the string that (I believe) you are talking about.
When the Router receives a connection request, it will attempt to map it via this table entry, if this is successful, then you are right, the router will create a client endpoint to talk to the ServiceEndpoint that you provided.