我正在使用WCF 4路由服务,需要以编程方式配置服务(而不是通过配置).我看到这样做的例子很少见,它创建了一个MessageFilterTable,如下所示:
var filterTable=new MessageFilterTable<IEnumerable<ServiceEndpoint>>();
Run Code Online (Sandbox Code Playgroud)
但是,该方法的泛型参数应该是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)));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2937 次 |
| 最近记录: |