What’s new in WCF 4.0

about.me/Chakravarthy
About ME
• MCA, MVP, MCPD, MCTS and CSM
• j.mp/CareerHistory
• Developer turned Architect
– WHAT !!
– Who else !!

• Community Person
Agenda
• What’s new !!??
– Configuration
– Tracing
– Serialization
– Message queuing
– Service discovery
– Routing
– Workflow services
Let’s start ..
What’s new in WCF
Kalpana (1948) is a Bollywood movie from a time before the term had been invented.
This 155-minute-long black-and-white feature film gives full rein to the talents of
choreographer Uday Shankar, the film’s director and a legend of Indian dance. The film is
about a young dancer who dreams of founding his own dance school, played by the
director himself. Despite living until the age of 76, Kalpana is the one and only film Uday
Shankar directed in his entire career. In the dance world, however, he will be
remembered as a veritable master of the art of choreography.
Kalpana will be screened at Cannes Classics on Thursday 17th May at 19:30, Salle BuƱuel.
Far from the world of Indian dancing, After the Curfew (1954) has as its backdrop the post-war
period in Indonesia. In the months following independence, Iskandar returns to civilian life. For this
medical student it is a time of bitter disillusionment, as he sees corruption and political
incompetence take hold throughout the country. The director, Usmar Ismail, is considered as one of
the forefathers of Indonesian cinema. He made a major contribution to the development of
Indonesian cinema in the 1950s by founding Perfini, the country’s first film studios.
After The Curfew will be screened at Cannes Classics on Thursday 17th May at 17:15, Salle BuƱuel.
??!!
a) Configuration Improvements
• Removed the need for explicit per-service
configuration
• default values for WCF bindings & behaviors
• the standard endpoint, which will allow you
to define reusable preconfigured endpoints

Source : http://j.mp/WCF4ConfigImp
Default bindings & behaviors

You can also
define default
binding and
behavior
configurations

• Simply define the binding/behavior without a name
• That binding takes effect for anything not assigned a
specific binding
• Can be defined at different scopes within config (e.g.
machine.config)

<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
Configuration Improvements

Source : http://j.mp/WCF4ConfigImp
File-less activation
• In WCF 4, you no longer need physical .svc files to
activate services
– Instead you can define a virtual mapping in config
<serviceHostingEnvironment>
<serviceActivations>
<add relativeAddress ="EntertainmentServices.svc"
service="EntertainmentShows"/>
</serviceActivations>
</serviceHostingEnvironment>
</system.serviceModel>
Default endpoints
• WCF 3.x services required at least one endpoint or you’d get
an exception
• WCF 4.0 services come with default endpoints
– One default endpoint per contract/base address combination
– Assuming you haven’t defined any manually
– If you’ve defined at least one endpoint, you won’t get default
endpoints
Standard endpoints
• WCF 4 also comes with several
ā€œpreconfiguredā€ standard endpoints
– These cover some of the most common usage
scenarios
– You can simply reuse them as-is without change

• You refer to standard endpoints by name using
the ā€œkindā€ attribute
– Makes it easier to get up and running in certain
scenarios
<endpoint kind ="mexEndpoint" address="mex" />
Formats and
Flexibility
multipart/form-data
text/calendar

application/atom+xml
image/svg+xml

application/json
Approx 900
text/directory
App media types!
application/xml

text/html

image/png

application/xaml+xml
application/x-www-form-urlencoded
preconfigured Standard endpoints
in v4.0
Standard endpoint name
mexEndpoint

dynamicEndpoint

discoveryEndpoint
udpDiscoveryEndpoint
announcementEndpoint

udpAnnouncementEndpoint
workflowControlEndpoint
webHttpEndpoint
webScriptEndpoint

Description
Defines a standard endpoint for MEX configured with IMetadataExchange for the service contract,
mexHttpBinding as the default binding (you can change this), and an empty address.
Defines a standard endpoint configured to use WCF Discovery within a WCF client application.
When using this standard endpoint, an address is not required because during the first call, the
client will query for a service endpoint matching the specified contract and automatically connect
to it for you.
Defines a standard endpoint that is pre-configured for discovery operations within a client
application. The user needs to specify the address and the binding when using this standard
endpoint.
Defines a standard endpoint that is pre-configured for discovery operations within a client
application using the UDP binding at a multicast address. Derives from DiscoveryEndpoint.
Defines a standard endpoint that is pre-configured for the announcement functionality of
discovery. The user needs to specify the address and the binding when using this standard
endpoint.
Defines a standard endpoint that is pre-configured for the announcement functionality over a UDP
binding at a multicast address. This endpoint derives from announcementEndpoint.
Defines a standard endpoint for controlling execution of workflow instances (create, run, suspend,
terminate, etc).
Defines a standard endpoint configured with WebHttpBinding and WebHttpBehavior. Use to
expose REST services.
Defines a standard endpoint configured with WebHttpBinding and WebScriptEnablingBehavior.
Use to expose Ajax services.
Default protocol mapping

<protocolMapping>
<add scheme="http" binding="basicHttpBinding" bindingConfiguration="" />
<add scheme="net.tcp" binding="netTcpBinding" bindingConfiguration=""/>
<add scheme="net.pipe" binding="netNamedPipeBinding" bindingConfiguration=""
<add scheme="net.msmq" binding="netMsmqBinding" bindingConfiguration=""/>
</protocolMapping>
How to choose a Binding
Yes
Yes
Local
Only

No

Inside
Firewall
& .NET
to .NET

No

Yes

No
MSMQ
Client
Support
Legacy?

Need to
Disconnect

Yes

NetTcp
Binding

Yes

No

No

NetMsmq
Binding

NetNamedPipe
Binding

Msmq
Integration
Binding

WsHttp
Binding

BasicHttp
Binding
Default behavior configuration
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior> <!-- notice no name attribute -->
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Routing
Service
Message Pump as a Service
Routing
Message
Service
Pump

Scenarios

Concerns

•
•
•
•
•

•
•
•
•
•

Basic Message Routing
Protocol Bridging
Service Aggregation
Versioning
…

Connection State
Security
Delivery Failure
Transactions
…
Message Routing

Echo

Routing
Service

Client

A
B
C

Time
Service

Supported Message Exchange Patterns

Multicast

Interface

Request Reply, Sessionful Request Reply

No

IRequestReplyRouter

OneWay

Yes

ISimplexDatagramRouter

Sessionful OneWay

Yes

ISimplexSessionRouter

Sessionful Duplex

Yes

IDuplexSessionRouter
Message Routing

Echo

Routing
Service

Client

MessageFilter

Endpoint

action == http://Message/Echo

Echo

action ==
http://Message/GetCurrentTime

TimeService

Filter On

MessageFilter

Action

ActionMessageFilter

Address header

AddressMessageFilter

Address header – longest prefix matching

AddressPrefixMessageFilter

Endpoint Name

EndpointNameMessageFilter

No Filter – matches everything

MatchAllMessageFilter

Logical And of two filters

StrictAndMessageFilter

XPath expression

XPathMessageFilter

Custom

Custom

Time
Service
Protocol Bridging

Routing
Service

Client
BasicHttp
SOAP 1.1

Service
Net.Tcp
SOAP 1.2
Security

Client

Routing
Service

Service
Error Handling
Echo
Service

Routing
Service

Client

Backup
Echo
Service
MessageFilter

Endpoint

action ==
http://Message/Echo

Echo

Alternate
Endpoints
Backup
EchoService
Router Service
• First-class "router" service
– Simply host the RoutingService class
– You host it like any other WCF service
– Configure with routing ā€œfiltersā€ to do content-based
routing
Hosting the RoutingService
• Additional routing service capabilities
– Protocol bridging (client sends over HTTP, router sends over TCP,
etc)
– Error handling support (router configured with backup endpoints)
– Multi-cast routing support (router sends to multiple endpoints)
Using the Routing Service
1.
2.

Create regular WCF Services to be called by the Routing Service.
Create a Routing Service:
a.
Change the markup in the .svc file to point to the routing Service.

Be sure to reference System.ServiceModel.Routing in your project
b.

In the web.config:
1)
Add endpoints for all the services to which you’ll connect in the <client>
section.

<client>
<endpoint name="CalculatorService1"
address="net.tcp://localhost:8001/servicemodelsamples/calcservice1"
binding="netTcpBinding"
contract="*" />
<endpoint name="CalculatorService2"
address="net.pipe://localhost/servicemodelsamples/calcservice2"
binding="netNamedPipeBinding"
contract="*" />
</client>
Using the Routing Service (cont’d)
b.

In the web.config (cont’d):
2)
Create a namespace filter and set the Xpath filterData

3)

Add filterTables to point to the correct end points

4)

Set the Routing behavior to identify the filterTables
WCF WebHttp
Services
Improved REST Support
• Many features in the WCF REST Starter Kit are now part of WCF 4.0

Automatic
help page

HTTP
caching

WCF/ASP.NE
T routes

Message
format
selection

REST project
templates

HTTP
ā€œfaultsā€

Various API
extensions
Automatic help page
• WCF 4 provides an automatic help page for REST services
– Configure the <webHttp> behavior with helpEnabled=ā€œtrueā€
Message format selection
• WCF 4 also provides automatic format selection for XML/JSON
– This feature is built on the HTTP ā€œAcceptā€ headers
<configuration>
<system.serviceModel>
<standardEndpoints>
<webHttpEndpoint>
<!-- the "" standard endpoint is used for auto creating
a web endpoint. -->
<standardEndpoint name="" helpEnabled="true"
automaticFormatSelectionEnabled="true"/>
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
</configuration>
WCF and ASP.NET routes
• WCF 4 provides the ability to integrate with the ASP.NET routing
engine
– You implement RegisterRoutes in Global.asax, add ServiceRoute
mappings
– ServiceRoute allows you to map a URL to a WCF 4 service class

• Ultimately this gives you a URL space that maps to multiple WCF
classes
private void RegisterRoutes()
{
WebServiceHostFactory factory = new
WebServiceHostFactory();
RouteTable.Routes.Add(new ServiceRoute("Bookmarks",
factory,
typeof(BookmarkService)));
RouteTable.Routes.Add(new ServiceRoute("Users", factory,
typeof(UserService)));
}
REST project templates
• Download the new REST project templates via the new Visual
Studio 2010 Extension Manager (Tools | Extension Manager)
•

Summary
WCF/WF 4.0 offers many improvements:
–
–
–
–
–

Simplified configuration
Discovery
Routing service
WebHttp services
Workflow services

• These improvements make WCF simpler and more
flexible
– Today’s common use cases just got easier
Thanks

What's new in Wcf4

  • 1.
    What’s new inWCF 4.0 about.me/Chakravarthy
  • 2.
    About ME • MCA,MVP, MCPD, MCTS and CSM • j.mp/CareerHistory • Developer turned Architect – WHAT !! – Who else !! • Community Person
  • 3.
    Agenda • What’s new!!?? – Configuration – Tracing – Serialization – Message queuing – Service discovery – Routing – Workflow services
  • 4.
  • 5.
  • 6.
    Kalpana (1948) isa Bollywood movie from a time before the term had been invented. This 155-minute-long black-and-white feature film gives full rein to the talents of choreographer Uday Shankar, the film’s director and a legend of Indian dance. The film is about a young dancer who dreams of founding his own dance school, played by the director himself. Despite living until the age of 76, Kalpana is the one and only film Uday Shankar directed in his entire career. In the dance world, however, he will be remembered as a veritable master of the art of choreography. Kalpana will be screened at Cannes Classics on Thursday 17th May at 19:30, Salle BuƱuel.
  • 7.
    Far from theworld of Indian dancing, After the Curfew (1954) has as its backdrop the post-war period in Indonesia. In the months following independence, Iskandar returns to civilian life. For this medical student it is a time of bitter disillusionment, as he sees corruption and political incompetence take hold throughout the country. The director, Usmar Ismail, is considered as one of the forefathers of Indonesian cinema. He made a major contribution to the development of Indonesian cinema in the 1950s by founding Perfini, the country’s first film studios. After The Curfew will be screened at Cannes Classics on Thursday 17th May at 17:15, Salle BuƱuel.
  • 8.
  • 10.
    a) Configuration Improvements •Removed the need for explicit per-service configuration • default values for WCF bindings & behaviors • the standard endpoint, which will allow you to define reusable preconfigured endpoints Source : http://j.mp/WCF4ConfigImp
  • 11.
    Default bindings &behaviors You can also define default binding and behavior configurations • Simply define the binding/behavior without a name • That binding takes effect for anything not assigned a specific binding • Can be defined at different scopes within config (e.g. machine.config) <behaviors> <serviceBehaviors> <behavior> <serviceMetadata httpGetEnabled="true"/> </behavior> </serviceBehaviors> </behaviors>
  • 12.
    Configuration Improvements Source :http://j.mp/WCF4ConfigImp
  • 13.
    File-less activation • InWCF 4, you no longer need physical .svc files to activate services – Instead you can define a virtual mapping in config <serviceHostingEnvironment> <serviceActivations> <add relativeAddress ="EntertainmentServices.svc" service="EntertainmentShows"/> </serviceActivations> </serviceHostingEnvironment> </system.serviceModel>
  • 14.
    Default endpoints • WCF3.x services required at least one endpoint or you’d get an exception • WCF 4.0 services come with default endpoints – One default endpoint per contract/base address combination – Assuming you haven’t defined any manually – If you’ve defined at least one endpoint, you won’t get default endpoints
  • 15.
    Standard endpoints • WCF4 also comes with several ā€œpreconfiguredā€ standard endpoints – These cover some of the most common usage scenarios – You can simply reuse them as-is without change • You refer to standard endpoints by name using the ā€œkindā€ attribute – Makes it easier to get up and running in certain scenarios <endpoint kind ="mexEndpoint" address="mex" />
  • 16.
  • 17.
    multipart/form-data text/calendar application/atom+xml image/svg+xml application/json Approx 900 text/directory App mediatypes! application/xml text/html image/png application/xaml+xml application/x-www-form-urlencoded
  • 18.
    preconfigured Standard endpoints inv4.0 Standard endpoint name mexEndpoint dynamicEndpoint discoveryEndpoint udpDiscoveryEndpoint announcementEndpoint udpAnnouncementEndpoint workflowControlEndpoint webHttpEndpoint webScriptEndpoint Description Defines a standard endpoint for MEX configured with IMetadataExchange for the service contract, mexHttpBinding as the default binding (you can change this), and an empty address. Defines a standard endpoint configured to use WCF Discovery within a WCF client application. When using this standard endpoint, an address is not required because during the first call, the client will query for a service endpoint matching the specified contract and automatically connect to it for you. Defines a standard endpoint that is pre-configured for discovery operations within a client application. The user needs to specify the address and the binding when using this standard endpoint. Defines a standard endpoint that is pre-configured for discovery operations within a client application using the UDP binding at a multicast address. Derives from DiscoveryEndpoint. Defines a standard endpoint that is pre-configured for the announcement functionality of discovery. The user needs to specify the address and the binding when using this standard endpoint. Defines a standard endpoint that is pre-configured for the announcement functionality over a UDP binding at a multicast address. This endpoint derives from announcementEndpoint. Defines a standard endpoint for controlling execution of workflow instances (create, run, suspend, terminate, etc). Defines a standard endpoint configured with WebHttpBinding and WebHttpBehavior. Use to expose REST services. Defines a standard endpoint configured with WebHttpBinding and WebScriptEnablingBehavior. Use to expose Ajax services.
  • 19.
    Default protocol mapping <protocolMapping> <addscheme="http" binding="basicHttpBinding" bindingConfiguration="" /> <add scheme="net.tcp" binding="netTcpBinding" bindingConfiguration=""/> <add scheme="net.pipe" binding="netNamedPipeBinding" bindingConfiguration="" <add scheme="net.msmq" binding="netMsmqBinding" bindingConfiguration=""/> </protocolMapping>
  • 20.
    How to choosea Binding Yes Yes Local Only No Inside Firewall & .NET to .NET No Yes No MSMQ Client Support Legacy? Need to Disconnect Yes NetTcp Binding Yes No No NetMsmq Binding NetNamedPipe Binding Msmq Integration Binding WsHttp Binding BasicHttp Binding
  • 21.
    Default behavior configuration <configuration> <system.serviceModel> <behaviors> <serviceBehaviors> <behavior><!-- notice no name attribute --> <serviceMetadata httpGetEnabled="true"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> </configuration>
  • 22.
  • 23.
    Message Pump asa Service Routing Message Service Pump Scenarios Concerns • • • • • • • • • • Basic Message Routing Protocol Bridging Service Aggregation Versioning … Connection State Security Delivery Failure Transactions …
  • 24.
    Message Routing Echo Routing Service Client A B C Time Service Supported MessageExchange Patterns Multicast Interface Request Reply, Sessionful Request Reply No IRequestReplyRouter OneWay Yes ISimplexDatagramRouter Sessionful OneWay Yes ISimplexSessionRouter Sessionful Duplex Yes IDuplexSessionRouter
  • 25.
    Message Routing Echo Routing Service Client MessageFilter Endpoint action ==http://Message/Echo Echo action == http://Message/GetCurrentTime TimeService Filter On MessageFilter Action ActionMessageFilter Address header AddressMessageFilter Address header – longest prefix matching AddressPrefixMessageFilter Endpoint Name EndpointNameMessageFilter No Filter – matches everything MatchAllMessageFilter Logical And of two filters StrictAndMessageFilter XPath expression XPathMessageFilter Custom Custom Time Service
  • 26.
  • 27.
  • 28.
  • 29.
    Router Service • First-class"router" service – Simply host the RoutingService class – You host it like any other WCF service – Configure with routing ā€œfiltersā€ to do content-based routing
  • 30.
    Hosting the RoutingService •Additional routing service capabilities – Protocol bridging (client sends over HTTP, router sends over TCP, etc) – Error handling support (router configured with backup endpoints) – Multi-cast routing support (router sends to multiple endpoints)
  • 31.
    Using the RoutingService 1. 2. Create regular WCF Services to be called by the Routing Service. Create a Routing Service: a. Change the markup in the .svc file to point to the routing Service. Be sure to reference System.ServiceModel.Routing in your project b. In the web.config: 1) Add endpoints for all the services to which you’ll connect in the <client> section. <client> <endpoint name="CalculatorService1" address="net.tcp://localhost:8001/servicemodelsamples/calcservice1" binding="netTcpBinding" contract="*" /> <endpoint name="CalculatorService2" address="net.pipe://localhost/servicemodelsamples/calcservice2" binding="netNamedPipeBinding" contract="*" /> </client>
  • 32.
    Using the RoutingService (cont’d) b. In the web.config (cont’d): 2) Create a namespace filter and set the Xpath filterData 3) Add filterTables to point to the correct end points 4) Set the Routing behavior to identify the filterTables
  • 34.
  • 35.
    Improved REST Support •Many features in the WCF REST Starter Kit are now part of WCF 4.0 Automatic help page HTTP caching WCF/ASP.NE T routes Message format selection REST project templates HTTP ā€œfaultsā€ Various API extensions
  • 36.
    Automatic help page •WCF 4 provides an automatic help page for REST services – Configure the <webHttp> behavior with helpEnabled=ā€œtrueā€
  • 37.
    Message format selection •WCF 4 also provides automatic format selection for XML/JSON – This feature is built on the HTTP ā€œAcceptā€ headers <configuration> <system.serviceModel> <standardEndpoints> <webHttpEndpoint> <!-- the "" standard endpoint is used for auto creating a web endpoint. --> <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/> </webHttpEndpoint> </standardEndpoints> </system.serviceModel> </configuration>
  • 38.
    WCF and ASP.NETroutes • WCF 4 provides the ability to integrate with the ASP.NET routing engine – You implement RegisterRoutes in Global.asax, add ServiceRoute mappings – ServiceRoute allows you to map a URL to a WCF 4 service class • Ultimately this gives you a URL space that maps to multiple WCF classes private void RegisterRoutes() { WebServiceHostFactory factory = new WebServiceHostFactory(); RouteTable.Routes.Add(new ServiceRoute("Bookmarks", factory, typeof(BookmarkService))); RouteTable.Routes.Add(new ServiceRoute("Users", factory, typeof(UserService))); }
  • 39.
    REST project templates •Download the new REST project templates via the new Visual Studio 2010 Extension Manager (Tools | Extension Manager)
  • 40.
    • Summary WCF/WF 4.0 offersmany improvements: – – – – – Simplified configuration Discovery Routing service WebHttp services Workflow services • These improvements make WCF simpler and more flexible – Today’s common use cases just got easier
  • 41.