WCF routing - how to add a filter table correctly

I use the WCF 4 routing service and you need to configure the program programmatically (as opposed to config via config). The examples I saw for this, which are rare, create a MessageFilterTable as follows:

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

But should the general parameter of this method be TFilterData (the type of data you are filtering)? I have my own custom filter that accepts a string - can I create a filter table this way?

If this works ... will the routing infrastructure create client endpoints from the list I'm moving to?

+3
source share
2 answers

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)));
+5

MSDN: How To:

, MessageFilterTable, FilterTable, RoutingConfiguration.

, :

rc.FilterTable.Add(new CustomMessageFilter("customStringParameter"), new List<ServiceEndpoint> { physicalServiceEndpoint });

CustomMessageFilter , "customStringParameter" - , ( ), . , , , , , ServiceEndpoint.

+2

All Articles