WCF ROUTING


Krunal Trivedi
Corporate Trainer For DotNet,Silverlight,SPS 2010
MCT S For .NET Web Technology
MCTS For SharePoint Server 2010 Development
Co-Founder at Aavid Technologies
Email:krunaltrivedi@live.in
Contact : 09998472789
Client Details
• The Routing Service is a generic SOAP intermediary that acts
  as a message router.



• This router / or the SOAP intermediary act as a client to the
  real Service and it works as a Service to the real client



• System.ServiceModel.Routing namespace.
• One of the challenges in Intermediary scenarios is that the
  internal endpoints may have different transport or SOAP
  version requirements than the endpoint that messages are
  received on.
• To support this scenario , the Routing Service can bridge
  protocols.
Filtering
• The WCF filtering system can use declarative filters to match
  messages and make operational decisions.
• You can use filters to determine what to do with a message
  by examining part of the message.
• A queuing process can use Xpath 1.0 query to check the
  priority element of a known header to determine whether to
  move a message to the front of the queue.
• The filtering system is composed of a set of classes that can
  efficiently determine which of a set of filters are true for a
  particular WCF messages.
• The filtering system is a core component of WCF messaging; it
  is designed to be extremely fast.
• Each filter implementation has been optimized for a
  particular kind of matching against WCF messages.
• Filtering is performed after a message is received and is part
  of dispatching message to the proper application component.
Filters
• The filter engine has two primary components
     filters
     Filters tables
• A filter makes Boolean decisions about a message based on user-
  specified logical condition.
• Filters implement the MessageFilter class.
• The Match methods are used to determine if a message satisfies a
  filter.
• One of the methods tests the message’s header but cannot inspect
  the message body.
• The other method takes a message buffer as an input parameter
  and can inspect the message body.
• The several kinds of filters each specialize in matching on a
  particular kind of Boolean condition. Once you construct a filter,
  you cannot change the criteria that a filter uses; to modify a filter's
  criteria, construct a new one and delete the existing filter.
Filter Tables
• Filter tables are used to store key-value pairs, where a filter is
  the key and some associated data is the value.
• The filter data can be used to indicate what actions to take if
  a message matches the filter and the type of the filter data is
  the generic parameter for the filter table class.
• The filter data can consist of routing rules, session security
  state, listeners on a channel, and so on.
• The data can be used where data flow control is necessary.
• Filter tables implement the generic
  interface IMessageFilterTable.
• Filter tables have several methods that match a message
  against all the filters in the table and return an unordered
  collection of matching filters or data.
• Some of the match methods are multiple-match and return
  all matching items. Others are single-match, returning only
  one item, and throw a MultipleFilterMatchesException if
  more than one filter matches.
• Action Filters:
• The ActionMessageFilter contains a list of action strings.
• If any of the actions in the filter’s list matches the Action
  header in the message or message buffer, the Match method
  returns true.
• If the list is empty, the filter is considered a match-all filter
  and any message or message buffer matches
  and Match returns true.
• If none of the actions in the filter’s list matches the Action
  header in the message or message
  buffer, Match returns false.
• If there is no action in the message and the filter’s list is non-
  empty, then Match returnsfalse.
• XPathMessageFilter (XPath queries against incoming
  messages)
• EndpointAddressMessageFilter and
  PrefixEndpointAddressMessageFilter (match
  against endpoint address)
Protocol Bridging
Stage-1…WCF Configless File
Create a console application “MessageService”
Add an interface…also Add Reference of System.ServiceModel
and import the namespace also
Add the Implementation class and implement interface
ConfigLess Hosting….
Run your server(console application…).copy and paste URI to your
browser….get the following screen..notice that proxy creation is disabled…
Add Reference of System.ServiceModel…Also Import the namespace and copy
and paste interface there…
Create a object of ChannelFactory….using object of interface
create a new channel….
Run your Server First…Run your client…You will get the message on the
Server…..
Change the binding to the WSHttpBinnding on the client…run the server…run the
client…observer the result….RUN TIME ERROR….




Limitation of ConfigLess WCF is..only for BasicHttpBinnding…not for
WSHttpBinding….That means config file is necessary for wsHttpBinding…configless
is not a Permanent solution.
• Stage-2…WCF Routing with Protocol Bridging
• Our objective is change BasicHttpBinding with WSHttpBinding
  on the server[so we have to drop configless setting].
• On server add new app.config file.Try to open it with
  Configuration Editor…but you can’t..so manually write
  configuration.
Add system.servicemodel
Add services tag
Add service tag inside services tag….add the attribute name where
name=MessageService.MessageServiceImpl(Namespace.ClassName)
Add endpoint inside service tag…which specifies address , binding,contract…
contract=MessageService.IProcessMessage(Namespace.Interface)
On the Server..modify main method…
On the Client…Make sure Binding is WSHttp…..
Run The Server…
Run the Client….
Need for Routing
Change address and binding on the server…
Note:We have address http://localhost:9000 and binding WSHttpBinding on the
client….Server side it is changed…so we required Routing…A Protocol Bridging




    Now ,if we run Server as well as Client application we get an error…the
    solution is SOAP Router….
Create a new console application…name it WCFRouter




                                            We want this to
                                            Listen to a certain endpoint
                                            And forward
                                            Over to the listener
Add reference of System.ServiceModel as well as
System.ServiceModel.Routing-----A Required NameSpace for Routing
RoutingService is responsible for routing messages between endpoints based on filter criteria.
ServiceHost provides a host for services….
Add app.config to the RouterProject
IRequestReplyRouter interface is required to process message from
Request-Reply channel

Address and Bindings are the same at the client—so this would be server for
client --Make sure on the server we have change d the address and binding
We are adding a Behavour
Filter tables are used to store key-value pairs, where a filter is the key and some
associated data is the value.
Gets or sets the name of the filter table used by this routing service for routing message




                                                  Behaviour section
Routing Section
Client Zone
Publish-Subscribe Mechanism
Copy-Paste MessageService and Rename it like MessageService2…
Modify app.config…observer address as well as service name
attribute
Open Server 1
Make Changes on the Client
Open WCF Router
Run Server1 , Run Server2, Run Router
        and Run Client Apps…

Wcf routing kt

  • 1.
    WCF ROUTING Krunal Trivedi CorporateTrainer For DotNet,Silverlight,SPS 2010 MCT S For .NET Web Technology MCTS For SharePoint Server 2010 Development Co-Founder at Aavid Technologies Email:krunaltrivedi@live.in Contact : 09998472789
  • 2.
  • 4.
    • The RoutingService is a generic SOAP intermediary that acts as a message router. • This router / or the SOAP intermediary act as a client to the real Service and it works as a Service to the real client • System.ServiceModel.Routing namespace.
  • 5.
    • One ofthe challenges in Intermediary scenarios is that the internal endpoints may have different transport or SOAP version requirements than the endpoint that messages are received on. • To support this scenario , the Routing Service can bridge protocols.
  • 6.
    Filtering • The WCFfiltering system can use declarative filters to match messages and make operational decisions. • You can use filters to determine what to do with a message by examining part of the message. • A queuing process can use Xpath 1.0 query to check the priority element of a known header to determine whether to move a message to the front of the queue. • The filtering system is composed of a set of classes that can efficiently determine which of a set of filters are true for a particular WCF messages.
  • 7.
    • The filteringsystem is a core component of WCF messaging; it is designed to be extremely fast. • Each filter implementation has been optimized for a particular kind of matching against WCF messages. • Filtering is performed after a message is received and is part of dispatching message to the proper application component.
  • 8.
    Filters • The filterengine has two primary components filters Filters tables
  • 9.
    • A filtermakes Boolean decisions about a message based on user- specified logical condition. • Filters implement the MessageFilter class. • The Match methods are used to determine if a message satisfies a filter. • One of the methods tests the message’s header but cannot inspect the message body. • The other method takes a message buffer as an input parameter and can inspect the message body. • The several kinds of filters each specialize in matching on a particular kind of Boolean condition. Once you construct a filter, you cannot change the criteria that a filter uses; to modify a filter's criteria, construct a new one and delete the existing filter.
  • 10.
    Filter Tables • Filtertables are used to store key-value pairs, where a filter is the key and some associated data is the value. • The filter data can be used to indicate what actions to take if a message matches the filter and the type of the filter data is the generic parameter for the filter table class. • The filter data can consist of routing rules, session security state, listeners on a channel, and so on. • The data can be used where data flow control is necessary. • Filter tables implement the generic interface IMessageFilterTable.
  • 11.
    • Filter tableshave several methods that match a message against all the filters in the table and return an unordered collection of matching filters or data. • Some of the match methods are multiple-match and return all matching items. Others are single-match, returning only one item, and throw a MultipleFilterMatchesException if more than one filter matches.
  • 12.
    • Action Filters: •The ActionMessageFilter contains a list of action strings. • If any of the actions in the filter’s list matches the Action header in the message or message buffer, the Match method returns true. • If the list is empty, the filter is considered a match-all filter and any message or message buffer matches and Match returns true. • If none of the actions in the filter’s list matches the Action header in the message or message buffer, Match returns false. • If there is no action in the message and the filter’s list is non- empty, then Match returnsfalse.
  • 13.
    • XPathMessageFilter (XPathqueries against incoming messages) • EndpointAddressMessageFilter and PrefixEndpointAddressMessageFilter (match against endpoint address)
  • 14.
  • 15.
  • 16.
    Create a consoleapplication “MessageService”
  • 17.
    Add an interface…alsoAdd Reference of System.ServiceModel and import the namespace also
  • 18.
    Add the Implementationclass and implement interface
  • 19.
  • 20.
    Run your server(consoleapplication…).copy and paste URI to your browser….get the following screen..notice that proxy creation is disabled…
  • 21.
    Add Reference ofSystem.ServiceModel…Also Import the namespace and copy and paste interface there…
  • 22.
    Create a objectof ChannelFactory….using object of interface create a new channel….
  • 23.
    Run your ServerFirst…Run your client…You will get the message on the Server…..
  • 24.
    Change the bindingto the WSHttpBinnding on the client…run the server…run the client…observer the result….RUN TIME ERROR…. Limitation of ConfigLess WCF is..only for BasicHttpBinnding…not for WSHttpBinding….That means config file is necessary for wsHttpBinding…configless is not a Permanent solution.
  • 25.
    • Stage-2…WCF Routingwith Protocol Bridging
  • 26.
    • Our objectiveis change BasicHttpBinding with WSHttpBinding on the server[so we have to drop configless setting]. • On server add new app.config file.Try to open it with Configuration Editor…but you can’t..so manually write configuration.
  • 28.
  • 29.
  • 30.
    Add service taginside services tag….add the attribute name where name=MessageService.MessageServiceImpl(Namespace.ClassName)
  • 31.
    Add endpoint insideservice tag…which specifies address , binding,contract… contract=MessageService.IProcessMessage(Namespace.Interface)
  • 32.
    On the Server..modifymain method…
  • 33.
    On the Client…Makesure Binding is WSHttp…..
  • 34.
    Run The Server… Runthe Client….
  • 35.
    Need for Routing Changeaddress and binding on the server… Note:We have address http://localhost:9000 and binding WSHttpBinding on the client….Server side it is changed…so we required Routing…A Protocol Bridging Now ,if we run Server as well as Client application we get an error…the solution is SOAP Router….
  • 36.
    Create a newconsole application…name it WCFRouter We want this to Listen to a certain endpoint And forward Over to the listener
  • 37.
    Add reference ofSystem.ServiceModel as well as System.ServiceModel.Routing-----A Required NameSpace for Routing
  • 38.
    RoutingService is responsiblefor routing messages between endpoints based on filter criteria. ServiceHost provides a host for services….
  • 39.
    Add app.config tothe RouterProject
  • 40.
    IRequestReplyRouter interface isrequired to process message from Request-Reply channel Address and Bindings are the same at the client—so this would be server for client --Make sure on the server we have change d the address and binding
  • 41.
    We are addinga Behavour
  • 42.
    Filter tables areused to store key-value pairs, where a filter is the key and some associated data is the value. Gets or sets the name of the filter table used by this routing service for routing message Behaviour section
  • 43.
  • 44.
  • 49.
    Publish-Subscribe Mechanism Copy-Paste MessageServiceand Rename it like MessageService2…
  • 50.
    Modify app.config…observer addressas well as service name attribute
  • 51.
  • 52.
    Make Changes onthe Client
  • 53.
  • 54.
    Run Server1 ,Run Server2, Run Router and Run Client Apps…