what's new in wcf4
TRANSCRIPT
About ME
• MCA, MVP, MCPD, MCTS and CSM• j.mp/CareerHistory• Developer turned Architect– WHAT !!– Who else !!
• Community Person
Agend
a
2.40
Agenda
• What’s new !!??– Configuration– Tracing– Serialization– Message queuing– Service discovery– Routing– Workflow services
Demo
3.40
Let’s start ..
WCF
!!??
4.40
What’s new in WCF
Kalpa
na
5.40
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.
After ..
6.40
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.
Huh !!
??
7.40
??!!
WCF
..
8.40
Confi
gurati
on
9.40
Source : http://j.mp/WCF4ConfigImp
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
Default
Bind
ing
10.40
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>
Confi
g Impr
ov
11.40
Source : http://j.mp/WCF4ConfigImp
Configuration Improvements
Filele
ss Acti
v
12.40
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>
Def En
dpoin
t
13.40
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
Std EP
s
14.40
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" />
Med
ia Fo
rmats
15.40
Formats and Flexibility
Appro
x 900
16.40
preC
onfig
EndP
oints
application/json
application/xml
application/atom+xml
image/png
text/directory
text/calendar
application/xaml+xml
text/html
image/svg+xml
multipart/form-data
application/x-www-form-urlencoded
Approx 900 App media types!
17.40
preconfigured Standard endpoints in v4.0
Standard endpoint name DescriptionmexEndpoint 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.
dynamicEndpoint
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.
discoveryEndpointDefines 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.
udpDiscoveryEndpoint 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.
announcementEndpointDefines 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.
udpAnnouncementEndpoint 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.
workflowControlEndpoint Defines a standard endpoint for controlling execution of workflow instances (create, run, suspend, terminate, etc).
webHttpEndpoint Defines a standard endpoint configured with WebHttpBinding and WebHttpBehavior. Use to expose REST services.
webScriptEndpoint Defines a standard endpoint configured with WebHttpBinding and WebScriptEnablingBehavior. Use to expose Ajax services.
Default
prot
ocol
18.40
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 2
Choo
se
19.40
How to choose a BindingInside
Firewall & .NET to .NET
Local Only
Yes No
Support Legacy?
YesNo
Yes NoNeed to
Disconnect
YesNo
NetTcp Binding
NetMsmq Binding
NetNamedPipe Binding
BasicHttp Binding
WsHttp Binding
MSMQ Client
Yes No
Msmq Integration
Binding
Def be
havio
r
20.40
Default behavior configuration
<configuration> <system.serviceModel> <behaviors> <serviceBehaviors> <behavior> <!-- notice no name attribute --> <serviceMetadata httpGetEnabled="true"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel></configuration>
Routi
ng Sr
v
21.40
RoutingService
Msg
Pump
22.40
Message Pump as a Service
Scenarios
• Basic Message Routing• Protocol Bridging• Service Aggregation• Versioning• …
Concerns
• Connection State• Security• Delivery Failure• Transactions• …
Message Pump
Inbound Channel Outbound Channel
RoutingService: A Message Pump Service for you to host, extend, and enjoy!
Routing Service
RoutingService
Msg
Rout
23.40
Message RoutingClient
TimeService
RoutingService
Echo
IRequestReplyRouter
BasicHttp
http://routinghost/routerABC
Supported Message Exchange Patterns Multicast Interface
Request Reply, Sessionful Request Reply No IRequestReplyRouter
OneWay Yes ISimplexDatagramRouter
Sessionful OneWay Yes ISimplexSessionRouter
Sessionful Duplex Yes IDuplexSessionRouter
Msg
Rout
24.40
Message Routing
MessageFilter Endpoint
action == http://Message/Echo Echo
action == http://Message/GetCurrentTime
TimeService
Client
TimeService
RoutingService
Echo
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
Replaceable atRuntime
Prot
ocol
Brdg
25.40
Protocol Bridging
Client ServiceRoutingService
BasicHttp Net.TcpSOAP 1.1 SOAP 1.2
Secu
rity
26.40
Security
Client ServiceRoutingService
Message sent usingClient Identity
Message sent usingRouting Service IdentityMessage sent usingClient Identity
Impersonation using WindowsIdentityToken
Err H
ndl
27.40
Error Handling
Client
BackupEcho
Service
RoutingService
EchoService
MessageFilter Endpoint AlternateEndpoints
action == http://Message/Echo
Echo BackupEchoService
Rout
Srv
28.40
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
Host R
ut Sr
v
29.40
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 R
ut Sr
v
30.40
Using the Routing Service1. Create regular WCF Services to be called by the Routing Service.2. 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> Usin
g cnt
..
31.40
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
Demo
32.40
Demo: Simple routing service example
DEMO
Web
Http Srvs
33.40
WCF WebHttpServices
REST
Supr
t
34.40
Improved REST Support
• Many features in the WCF REST Starter Kit are now part of WCF 4.0
Automatic help page
HTTP caching
Message format
selection
HTTP “faults”
WCF/ASP.NET routes
REST project templates
Various API extensions
Auto H
elp Pg
35.40
Automatic help page
• WCF 4 provides an automatic help page for REST services– Configure the <webHttp> behavior with helpEnabled=“true”
Msg
Form
at Se
l
36.40
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
& ASP
Ruts
37.40
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))); }
38.40
REST
Prj T
mpl
REST project templates
• Download the new REST project templates via the new Visual Studio 2010 Extension Manager (Tools | Extension Manager)
39.40
Summar
y
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
Than
ks
40.40
Thanks
Than
ks