SlideShare a Scribd company logo
WCF 4.0 Eyal Vardi CEO E4D Solutions LTD Microsoft MVP Visual C# blog: www.eVardi.com
Agenda Simplified Configuration Serialization Improvements  Discovery Routing Services Web Http Programming
Simplified Configuration
Simplified Configuration using   (   var  host  =   new  ServiceHost (   typeof (  CalculatorService  ) , new  Uri (   &quot;http://localhost:1234/Service&quot;  ) , new  Uri (   &quot;net.tcp://localhost:4321/Service&quot;  )  ) ) { host.Open(); Console .WriteLine(  &quot;The service is ready.&quot;  ); Console .WriteLine(   &quot;Press <ENTER> to terminate service.&quot;  );   Console .ReadKey(); host.Close(); } The service is open with default binding & behaviors
Explicitly & Default Endpoints using   (   var  host  =   new  ServiceHost (   typeof (  CalculatorService  ) ) ) {   host.AddDefaultEndpoints();  host.Open(); } < services > < service   name = &quot; CalculatorService &quot; > < host > < baseAddresses > < add   baseAddress = &quot; http://localhost:1234/Service &quot; /> < add   baseAddress = &quot; net.tcp://localhost:4321/Service &quot; /> </ baseAddresses > </ host >  </ service > </ services > Config File Default Endpoint
Default Endpoint In WEB
Default Profile < bindings >    < basicHttpBinding >       < binding   maxReceivedMessageSize = &quot; 9999999 &quot; >          < readerQuotas   maxArrayLength = &quot; 9999999 &quot; />       </ binding >    </ basicHttpBinding >       </ bindings > < services > < service   name = &quot; CalculatorService &quot; > < host > < baseAddresses > < add   baseAddress = &quot; http://localhost:1234/Service &quot; /> < add   baseAddress = &quot; net.tcp://localhost:4321/Service &quot; /> </ baseAddresses > </ host >  </ service > </ services > No Name !!! Default profile for BasicHttpBinding
Protocol Mapping < protocolMapping >   < add   scheme = &quot; http &quot;   binding = &quot; basicHttpBinding &quot; />   < add   scheme = &quot; net.tcp &quot;   binding = &quot; netTcpBinding &quot; />   < add   scheme = &quot; net.pipe &quot;   binding = &quot; netNamedPipeBinding &quot; />   < add   scheme = &quot; net.msmq &quot;   binding = &quot; netMsmqBinding &quot; /> </ protocolMapping > < services > < service   name = &quot; CalculatorService &quot; > < host > < baseAddresses > < add   baseAddress = &quot; http://localhost:1234/Service &quot; /> < add   baseAddress = &quot; net.tcp://localhost:4321/Service &quot; /> </ baseAddresses > </ host >  </ service > </ services >
Protocol Mapping < protocolMapping >   < add   scheme = &quot; http &quot;   binding = &quot; wsHttpBinding &quot; bindingConfiguration = &quot; wsHttpBinding &quot;  /> </ protocolMapping > < services > < service   name = &quot; CalculatorService &quot; > < host > < baseAddresses > < add   baseAddress = &quot; http://localhost:1234/Service &quot; /> < add   baseAddress = &quot; net.tcp://localhost:4321/Service &quot; /> </ baseAddresses > </ host >  </ service > </ services >
Simplified Configuration
File-less Activation (no .svc) It possible to define virtual service activation endpoints that map to your WCF service. ServiceHostingEnvironment is an application level config.  Supports activation over both http and non-http protocol. Requires  extensions  in the relatativeAddress i.e. .svc. < serviceHostingEnvironment >        < serviceActivations >          < add   relativeAddress =&quot;~/E4D.svc&quot;  service =&quot;E4d.Hello&quot;/>        </ serviceActivations >      </ serviceHostingEnvironment >
File-less Activation
Kind Attribute Set the type of the standard endpoint Type of kinds: mexEndpoint discoveryEndpoint announcementEndpoint udpDiscoveryEndpoint udpAnnouncementEndpoint webHttpEndpoint < service   name =&quot;HelloService&quot;>      ...      < endpoint   binding =&quot;webHttpBinding&quot;  contract = &quot;IService1&quot; kind = &quot;webHttpEndpoint&quot; /> < endpoint   kind =&quot;mexEndpoint&quot; />  </ service > No need in bindingConfiguration endpointConfiguration
Standard Endpoint Setting < service   name =&quot;HelloService&quot;>      < endpoint     kind =&quot;udpDiscoveryEndpoint&quot;   endpointConfiguration =&quot;MyEndpointSettings&quot; /> </ service > < standardEndpoints >    < udpDiscoveryEndpoint >        < standardEndpoint  name =&quot;MyEndpointSettings&quot;              multicastAddress =&quot;soap.udp://239.255.255.252:3704&quot;              maxResponseDelay =&quot;00:00:02&quot;>             < transportSettings                    duplicateMessageHistoryLength =&quot;2048&quot;                    maxPendingMessageCount =&quot;5&quot;                    maxReceivedMessageSize =&quot;8192&quot;                    maxBufferPoolSize =&quot;262144&quot;/>            </ standardEndpoint >     </ udpDiscoveryEndpoint > </ standardEndpoints >
Custom Standard Endpoint  Standard endpoint must be registered in the  <endpointExtensions>  section. < system.serviceModel >  < service   name =&quot;HelloService&quot;>      < endpoint   kind =  &quot; udpDiscoveryEndpoint &quot;  />   </ service >    < extensions >        < endpointExtensions >          < add   name = &quot; udpDiscoveryEndpoint &quot;   type = &quot; ... &quot;  />        </ endpointExtensions >     </ extensions >  </ system.serviceModel >
Standard Endpoint
Service Discovery
Why We Need Discovery?
Async WCF Services
WS – Discovery Service Opened Client Target Service Client Client Target Service Target Service Hello
WS – Discovery Client Look for Service Client Target Service Client Client Target Service Target Service Probe
WS – Discovery Service Return Match Message Client Target Service Client Client Target Service Target Service Probe Match
WS – Discovery Service Closed Client Target Service Client Client Target Service Target Service By
Multicast, Broadcast & Unicast Multicast Broadcast Unicast
WCF With Discovery Server Side Normal endpoints with  EndpointDiscoveryBehavior Discovery endpoint with ServiceDiscoveryBehavior Target  Service
WCF With Discovery Server Side < system.serviceModel > < service   name =&quot;HelloService&quot;> < endpoint address  = &quot;net.tcp://localhost/&quot; binding  = &quot;netTcpBinding&quot; contract  = &quot;ICalculator&quot;  />       < endpoint   kind  =  &quot; udpDiscoveryEndpoint &quot;  />   </ service >    </ behaviors >  < serviceBehaviors > < behavior > < serviceDiscovery  /> </ behavior > </ serviceBehaviors > </ behaviors >  </ system.serviceModel >
Create discovery client Define the search Criteria for the client Choose endpoint, from the search result. WCF With Discovery Client Side  ( Two steps ) var  client  = new  DiscoveryClient (  new  UdpDiscoveryEndpoint () ); var  criteria   =  new  FindCriteria (  typeof (   ICalculatorService   ) ); FindResponse  findResponse = client.Find( criteria ); var  address  = findResponse.Endpoints[0].Address  Binding? ListenUri? Scope?
Basic Discovery
How to Know About The Binding? Add MEX  endpoint Discovery the MEX endpoint Use the  MetadataResolver  to resolve the binding. ServiceEndpointCollection   endpoints =     MetadataResolver .Resolve(  typeof ( IHelloService ), mexAddress );
Dynamic Endpoint DiscoveryClientBindingElement  is added to the binding you specify in the  DynamicEndpoint  constructor, if not already present.  var  dynamicEndpoint =  new   DynamicEndpoint ( ContractDescription .GetContract(  typeof ( ICalc ) ), new   NetTcpBinding () ); dynamicEndpoint.FindCriteria.Scopes.Add(...); var  client =  new  CalcClient ( dynamicEndpoint );
Dynamic Endpoint
Discovery Announcements < service   name =&quot;HelloService&quot;>      ...      < endpoint   name =&quot;udpDiscovery“  kind =&quot;udpDiscoveryEndpoint&quot;/> </ service > ... < serviceBehaviors >    < behavior >       < serviceDiscovery >          < announcementEndpoints >             < endpoint   name  =  &quot; udpAnnouncement &quot;   kind  =  &quot; udpAnnouncementEndpoint &quot; />             </ announcementEndpoints >          </ serviceDiscovery >    </ behavior > </ serviceBehaviors >  Server Side:
Discovery Announcements var  announcementService  = new  AnnouncementService (); announcementService.OnlineAnnouncementReceived   += OnOnlineEvent; announcementService.OfflineAnnouncementReceived   +=   OnOfflineEvent; using  (  var  host  = new  ServiceHost ( announcementService   ) ) { host.AddServiceEndpoint(  new  UdpAnnouncementEndpoint () ); host.Open(); ... } Consumers Side:
Discovery Announcements
Announcement Data
Discovery Proxy Managed discovery allows you to locate services no matter where they are, as long as they are registered with a discovery proxy. Client Target Service Client Client Target Service Target Service Discovery Proxy Hello
Discovery Proxy Managed discovery allows you to locate services no matter where they are, as long as they are registered with a discovery proxy. Client Target Service Client Client Target Service Target Service Discovery Proxy Probe
Discovery Proxy Managed discovery allows you to locate services no matter where they are, as long as they are registered with a discovery proxy. Client Target Service Client Client Target Service Target Service Discovery Proxy Probe Match
Discovery Proxy Managed discovery allows you to locate services no matter where they are, as long as they are registered with a discovery proxy. Client Target Service Client Client Target Service Target Service Discovery Proxy By
Discovery Proxy
Service Discovery When service is open he send to MDC a message ( Endpoint info).  When Service look for a service he ask the MDC. Unified Cache View
Solution Advantage No need to do multicast communication The server endpoints info is available  to all the services immediate after the server is open, ( no need to do communication ). When the service is unavailable (down time)  the endpoint info will still be available
Routing Services
Why a Router Service? Load balancing Priority routing to application pools or servers according to message content. Partitioning services so that messages targeting operations can be handled by different application pools or servers.
Router Service Architecture  Server C Server C Server  B Client Router Service Filter Tables Filters Service A Service B Service C
Router Endpoints & Contracts < service   name  = &quot; System.ServiceModel.Routing.RoutingService &quot; >    < endpoint   name  = &quot;reqReplyEndpoint &quot; address   =  &quot;&quot;   binding   =  &quot; basicHttpBinding &quot;   contract  =  &quot; System.ServiceModel.Routing.IRequestReplyRouter &quot;     /> </ service >
Configuring Filters The  RouterService  evaluates  filters  to determine how to forward the message. < serviceBehaviors >  < behavior > < routing   filterTableName = &quot; MyRoutingTable &quot;  /> </ behavior > </ serviceBehaviors > < routing > < filters > < filter   name =&quot;MatchAllFilter1&quot;  filterType =&quot;MatchAll&quot; /> </ filters > < filterTables > < filterTable   name =&quot;MyroutingTable&quot;> < add   filterName =&quot;MatchAllFilter1&quot;  endpointName =&quot;CalculatorService&quot; /> </ filterTable > </ filterTables > </ routing > < client >  < endpoint  name =&quot;CalculatorService&quot;    address =&quot;http://...&quot;    binding =&quot;basicHtttpBinding&quot;  contract =&quot;*&quot; > </ client >
Message Filter Compares the &quot;To&quot; & Headers address to the endpoint address Compares the incoming &quot;Action&quot; value against the actions on the contract
Message Filter Compares the &quot;To&quot; & Headers address to the endpoint address Compares the incoming &quot;Action&quot; value against the actions on the contract < filters >  < filter  name =&quot;addFilter&quot;  filterType =&quot;XPath&quot;   filterData =&quot;...&quot; > < filter  name =&quot;addFilter&quot;  filterType =&quot;Action&quot;  filterData =&quot;...&quot; > </ filters >
Filtering architecture
Binding Configuration  The router typically does not process protocol headers passed by the client. Security Reliable sessions Transactions Other related protocols.
Routing Services
Error Handing You can define different lists of alternate endpoints that will be used if communicating with the initial target endpoint results in an error.  < routing > ...  < filterTable   name =&quot;MyroutingTable&quot;> < add   filterName  =&quot;f1&quot;    endpointName  =&quot;t1&quot;  backupList  =&quot;altEndpoints&quot; />  </ filterTable > ... < backupLists >          < backupList  name =&quot;altEndpoints&quot;>              < add   endpointName =&quot;CalculatorService2&quot;/>                    </ backupList >        </ backupLists > </ routing >
Multicast Routing Behavior Supports automatically routing a particular incoming message to multiple destinations in a “multicast” fashion. < routing > < filters > < filter   name =&quot;Filter1&quot;  filterType =&quot;MatchAll&quot; /> </ filters > < filterTables > < filterTable   name =&quot;MyroutingTable&quot;> < add   filterName =&quot;Filter1&quot;  endpointName =&quot;Target1&quot; /> < add   filterName =&quot;Filter1&quot;  endpointName =&quot;Target2&quot; /> < add   filterName =&quot;Filter1&quot;  endpointName =&quot;Target3&quot; /> </ filterTable > </ filterTables > </ routing > “ Multicast”
Higher Default Throttling Settings MaxConcurrent Sessions  10    100 * CPU MaxConcurrent Calls  16   16  * CPU MaxConcurrent Instances  26    116 * CPU
Serialization Improvements
Serialization Improvements public  UserInfo  EchoUser ( int  userId  ); Encoding Deserialization Serialization Encoding Binding Transport
KnownType Attribute  Make sure a type is included in the serialization stream [  ServieContract  ] public intrface  IMedia   {   [  OperationContract  ]  Media  GetMedia(  Media  media );  }  [  DataContract  ]  public class  Media   { ... } [  DataContract  ]   public class  DVD  :  Media   { ... }  [  DataContract  ]   public class  CD  :  Media   { ... }  < Envelope > < Header > < Action >E4D/IMedia/GetMedia</ Action > </ Header > < Body > < GetMedia > < media > < Name>Madona </ Name > < Type>CDWR </ Type > </ media > </ GetMedia > </ Body > </ Envelope >
[  ServieContract  ] public intrface  IMedia   {   [  OperationContract  ]  Media  GetMedia(  Media  media );  } [  DataContract  ]  public class  Media   { ... } [  DataContract  ]   public class  DVD  :  Media   { ... }  [  DataContract  ]   public class  CD  :  Media   { ... }  < Envelope > < Header > < Action >E4D/IMedia/GetMedia</ Action > </ Header > < Body > < GetMedia > < media   type =&quot;CD&quot;> < Name>Madona </ Name > < Type>CDWR </ Type > </ media > </ GetMedia > </ Body > </ Envelope >
KnownType Attribute  Make sure a type is included in the serialization stream [  ServieContract  ] public intrface  IMedia   {   [  OperationContract  ]  Media  GetMedia(  Media  media );  }  [  DataContract  ]  [  KnownType (  typeof ( DVD ) )]   [  KnownType (  typeof ( CD ) ) ]   public class  Media   { ... } [  DataContract  ]   public class  DVD  :  Media   { ... }  [  DataContract  ]   public class  CD  :  Media   { ... }  < Envelope > < Header > < Action >E4D/IMedia/GetMedia</ Action > </ Header > < Body > < GetMedia > < media   type =&quot;CD&quot;> < Name>Madona </ Name > < Type>CDWR </ Type > </ media > </ GetMedia > </ Body > </ Envelope > Known Type
The Serialization in WCF 3.5
The Serialization in WCF 4.0
Data Contract Resolver New types  can be added at  runtime  using the  xsi:type  schema declarations.  The  ResolveType  method is invoked only during serialization and is used to map any type to a new  xsi:type  name. The  ResolveName  method is used only during deserialization and allows you to map any  xsi:type  information to a type.
Data Contract Resolver
Web Http Programming
Enhanced REST Support Caching support in IIS/WAS Dynamic content types Improved exception support JSONP support for AJAX Services Automatically generated help page ASP.NET Routing integration Helper methods for creating content
Help Page  < behaviors > < endpointBehaviors > < behavior   name = &quot; HelpBehavior &quot; > < webHttp   enableHelp = &quot; true &quot; /> </ behavior > </ endpointBehaviors > </ behaviors >
Caching < system.web > < caching > < outputCacheSettings > < outputCacheProfiles > < add   name   =  &quot; CacheFor60Seconds &quot;     duration   =  &quot; 60 &quot;     varyByParam  =  &quot; format &quot; /> </ outputCacheProfiles > </ outputCacheSettings > </ caching > </ system.web > [ AspNetCacheProfile (&quot; CacheFor60Seconds &quot;)] [ WebGet ] [ OperationContract ] public Counter  GetItem(){...}
Help Page
JSONP For AJAX Services Convention used to invoke cross-domain scripts by generating script tags in the current document. Result is returned in a specified callback function <script src=&quot;http://...&quot;> can evaluate scripts from any domain. < serviceHostingEnvironment   aspNetCompatibilityEnabled =&quot;true&quot;/> < standardEndpoints > < webScriptEndpoint > < standardEndpoint   crossDomainScriptAccessEnabled =&quot;true&quot;/> </ webScriptEndpoint > </ standardEndpoints >
JSONP
Dynamic Content WCF can automatically create response format  based on  Content-Type  and  Accepts  headers. Helper methods for creating content Available through  WebOperationContext public Message CreateAtom10Response(...); public Message CreateJsonResponse<T>(...); public Message CreateStreamResponse(...); public Message CreateTextResponse(...); public Message CreateXmlResponse(...); public Message CreateXmlResponse<T>(...);
Dynamic Content
Resources http://blogs.microsoft.co.il/blogs/vardi/ A Developer’s Introduction to WCF 4 Beta 1 Service Configuration Improvements in .NET 4 What’s New in WCF 4.0? Jesus Rodriguez's WebLog

More Related Content

PPTX
WCF - In a Week
PPT
Svcc2009 Async Ws
PPT
Esposito Ajax Remote
PPT
AJAX ASP.Net
 
PPT
Web Services Part 2
PPT
Business Process Execution Language
PPTX
Advanced WCF Workshop
PDF
Wcf development
WCF - In a Week
Svcc2009 Async Ws
Esposito Ajax Remote
AJAX ASP.Net
 
Web Services Part 2
Business Process Execution Language
Advanced WCF Workshop
Wcf development

Viewers also liked (18)

PPTX
Windows Communication Foundation (WCF)
PPT
An Overview Of Wpf
PPS
Wcf Transaction Handling
PPTX
Advanced WCF
PDF
Beginning with wcf service
PPT
Wcf architecture overview
PPTX
Wcf for the web developer
PDF
Angularjs interview questions and answers
DOCX
Angular.js interview questions
PPT
2 Day - WPF Training by Adil Mughal
PPT
Threads c sharp
PPTX
WPF For Beginners - Learn in 3 days
PPTX
WCF (Windows Communication Foundation)
PDF
ASP.NET MVC Interview Questions and Answers by Shailendra Chauhan
PPTX
WCF Security, FSec
PPTX
WCF Fundamentals
PDF
Windows Communication Foundation (WCF)
PDF
29 Essential AngularJS Interview Questions
Windows Communication Foundation (WCF)
An Overview Of Wpf
Wcf Transaction Handling
Advanced WCF
Beginning with wcf service
Wcf architecture overview
Wcf for the web developer
Angularjs interview questions and answers
Angular.js interview questions
2 Day - WPF Training by Adil Mughal
Threads c sharp
WPF For Beginners - Learn in 3 days
WCF (Windows Communication Foundation)
ASP.NET MVC Interview Questions and Answers by Shailendra Chauhan
WCF Security, FSec
WCF Fundamentals
Windows Communication Foundation (WCF)
29 Essential AngularJS Interview Questions
Ad

Similar to WCF 4.0 (20)

ODP
Interoperable Web Services with JAX-WS
PPT
Neil Patel - What You Need to be Measuring and How to Do It
PPT
Vb.Net Web Forms
PDF
Service Oriented Integration With ServiceMix
ZIP
GTAC: AtomPub, testing your server implementation
ODP
JUDCon London 2011 - Bin packing with drools planner by example
PPT
Web APIs & Google APIs
PPT
Ajax ons2
PPT
Migration testing framework
ODP
10 Things You're Not Doing [IBM Lotus Notes Domino Application Development]
PPTX
A Web Developer's Journey across different versions of ASP.NET
ODP
jBPM5 in action - a quickstart for developers
PPT
Struts2
PPT
JSP diana y yo
PPTX
ASP.NET MVC
PPT
Php Crash Course
PPT
Controls
PPTX
Using Forms in Share
PPTX
Moving applications to the cloud
Interoperable Web Services with JAX-WS
Neil Patel - What You Need to be Measuring and How to Do It
Vb.Net Web Forms
Service Oriented Integration With ServiceMix
GTAC: AtomPub, testing your server implementation
JUDCon London 2011 - Bin packing with drools planner by example
Web APIs & Google APIs
Ajax ons2
Migration testing framework
10 Things You're Not Doing [IBM Lotus Notes Domino Application Development]
A Web Developer's Journey across different versions of ASP.NET
jBPM5 in action - a quickstart for developers
Struts2
JSP diana y yo
ASP.NET MVC
Php Crash Course
Controls
Using Forms in Share
Moving applications to the cloud
Ad

More from Eyal Vardi (20)

PPTX
Why magic
PPTX
Smart Contract
PDF
Rachel's grandmother's recipes
PPTX
Performance Optimization In Angular 2
PPTX
Angular 2 Architecture (Bucharest 26/10/2016)
PPTX
Angular 2 NgModule
PPTX
Upgrading from Angular 1.x to Angular 2.x
PPTX
Angular 2 - Ahead of-time Compilation
PPTX
Routing And Navigation
PPTX
Angular 2 Architecture
PPTX
Angular 1.x vs. Angular 2.x
PPTX
Angular 2.0 Views
PPTX
Component lifecycle hooks in Angular 2.0
PPTX
Template syntax in Angular 2.0
PPTX
Http Communication in Angular 2.0
PPTX
Angular 2.0 Dependency injection
PPTX
Angular 2.0 Routing and Navigation
PPTX
Async & Parallel in JavaScript
PPTX
Angular 2.0 Pipes
PPTX
Angular 2.0 forms
Why magic
Smart Contract
Rachel's grandmother's recipes
Performance Optimization In Angular 2
Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 NgModule
Upgrading from Angular 1.x to Angular 2.x
Angular 2 - Ahead of-time Compilation
Routing And Navigation
Angular 2 Architecture
Angular 1.x vs. Angular 2.x
Angular 2.0 Views
Component lifecycle hooks in Angular 2.0
Template syntax in Angular 2.0
Http Communication in Angular 2.0
Angular 2.0 Dependency injection
Angular 2.0 Routing and Navigation
Async & Parallel in JavaScript
Angular 2.0 Pipes
Angular 2.0 forms

Recently uploaded (20)

PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Advanced Soft Computing BINUS July 2025.pdf
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Big Data Technologies - Introduction.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
PDF
cuic standard and advanced reporting.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
20250228 LYD VKU AI Blended-Learning.pptx
Empathic Computing: Creating Shared Understanding
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Unlocking AI with Model Context Protocol (MCP)
Advanced Soft Computing BINUS July 2025.pdf
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
The AUB Centre for AI in Media Proposal.docx
NewMind AI Weekly Chronicles - August'25 Week I
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Big Data Technologies - Introduction.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
NewMind AI Monthly Chronicles - July 2025
Diabetes mellitus diagnosis method based random forest with bat algorithm
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
cuic standard and advanced reporting.pdf
MYSQL Presentation for SQL database connectivity
Network Security Unit 5.pdf for BCA BBA.
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...

WCF 4.0

  • 1. WCF 4.0 Eyal Vardi CEO E4D Solutions LTD Microsoft MVP Visual C# blog: www.eVardi.com
  • 2. Agenda Simplified Configuration Serialization Improvements Discovery Routing Services Web Http Programming
  • 4. Simplified Configuration using ( var host = new ServiceHost ( typeof ( CalculatorService ) , new Uri ( &quot;http://localhost:1234/Service&quot; ) , new Uri ( &quot;net.tcp://localhost:4321/Service&quot; ) ) ) { host.Open(); Console .WriteLine( &quot;The service is ready.&quot; ); Console .WriteLine( &quot;Press <ENTER> to terminate service.&quot; ); Console .ReadKey(); host.Close(); } The service is open with default binding & behaviors
  • 5. Explicitly & Default Endpoints using ( var host = new ServiceHost ( typeof ( CalculatorService ) ) ) { host.AddDefaultEndpoints(); host.Open(); } < services > < service name = &quot; CalculatorService &quot; > < host > < baseAddresses > < add baseAddress = &quot; http://localhost:1234/Service &quot; /> < add baseAddress = &quot; net.tcp://localhost:4321/Service &quot; /> </ baseAddresses > </ host > </ service > </ services > Config File Default Endpoint
  • 7. Default Profile < bindings >    < basicHttpBinding >      < binding maxReceivedMessageSize = &quot; 9999999 &quot; >          < readerQuotas maxArrayLength = &quot; 9999999 &quot; />       </ binding >    </ basicHttpBinding >      </ bindings > < services > < service name = &quot; CalculatorService &quot; > < host > < baseAddresses > < add baseAddress = &quot; http://localhost:1234/Service &quot; /> < add baseAddress = &quot; net.tcp://localhost:4321/Service &quot; /> </ baseAddresses > </ host > </ service > </ services > No Name !!! Default profile for BasicHttpBinding
  • 8. Protocol Mapping < protocolMapping >   < add scheme = &quot; http &quot; binding = &quot; basicHttpBinding &quot; />   < add scheme = &quot; net.tcp &quot; binding = &quot; netTcpBinding &quot; />   < add scheme = &quot; net.pipe &quot; binding = &quot; netNamedPipeBinding &quot; />   < add scheme = &quot; net.msmq &quot; binding = &quot; netMsmqBinding &quot; /> </ protocolMapping > < services > < service name = &quot; CalculatorService &quot; > < host > < baseAddresses > < add baseAddress = &quot; http://localhost:1234/Service &quot; /> < add baseAddress = &quot; net.tcp://localhost:4321/Service &quot; /> </ baseAddresses > </ host > </ service > </ services >
  • 9. Protocol Mapping < protocolMapping >   < add scheme = &quot; http &quot; binding = &quot; wsHttpBinding &quot; bindingConfiguration = &quot; wsHttpBinding &quot; /> </ protocolMapping > < services > < service name = &quot; CalculatorService &quot; > < host > < baseAddresses > < add baseAddress = &quot; http://localhost:1234/Service &quot; /> < add baseAddress = &quot; net.tcp://localhost:4321/Service &quot; /> </ baseAddresses > </ host > </ service > </ services >
  • 11. File-less Activation (no .svc) It possible to define virtual service activation endpoints that map to your WCF service. ServiceHostingEnvironment is an application level config. Supports activation over both http and non-http protocol. Requires extensions in the relatativeAddress i.e. .svc. < serviceHostingEnvironment >       < serviceActivations >         < add relativeAddress =&quot;~/E4D.svc&quot; service =&quot;E4d.Hello&quot;/>       </ serviceActivations >     </ serviceHostingEnvironment >
  • 13. Kind Attribute Set the type of the standard endpoint Type of kinds: mexEndpoint discoveryEndpoint announcementEndpoint udpDiscoveryEndpoint udpAnnouncementEndpoint webHttpEndpoint < service name =&quot;HelloService&quot;>      ...      < endpoint binding =&quot;webHttpBinding&quot; contract = &quot;IService1&quot; kind = &quot;webHttpEndpoint&quot; /> < endpoint kind =&quot;mexEndpoint&quot; /> </ service > No need in bindingConfiguration endpointConfiguration
  • 14. Standard Endpoint Setting < service name =&quot;HelloService&quot;>      < endpoint kind =&quot;udpDiscoveryEndpoint&quot; endpointConfiguration =&quot;MyEndpointSettings&quot; /> </ service > < standardEndpoints >    < udpDiscoveryEndpoint >        < standardEndpoint name =&quot;MyEndpointSettings&quot;              multicastAddress =&quot;soap.udp://239.255.255.252:3704&quot;              maxResponseDelay =&quot;00:00:02&quot;>             < transportSettings                   duplicateMessageHistoryLength =&quot;2048&quot;                   maxPendingMessageCount =&quot;5&quot;                   maxReceivedMessageSize =&quot;8192&quot;                   maxBufferPoolSize =&quot;262144&quot;/>            </ standardEndpoint >     </ udpDiscoveryEndpoint > </ standardEndpoints >
  • 15. Custom Standard Endpoint Standard endpoint must be registered in the <endpointExtensions> section. < system.serviceModel > < service name =&quot;HelloService&quot;>      < endpoint kind = &quot; udpDiscoveryEndpoint &quot; /> </ service >   < extensions >       < endpointExtensions >         < add name = &quot; udpDiscoveryEndpoint &quot;   type = &quot; ... &quot; />       </ endpointExtensions >    </ extensions > </ system.serviceModel >
  • 18. Why We Need Discovery?
  • 20. WS – Discovery Service Opened Client Target Service Client Client Target Service Target Service Hello
  • 21. WS – Discovery Client Look for Service Client Target Service Client Client Target Service Target Service Probe
  • 22. WS – Discovery Service Return Match Message Client Target Service Client Client Target Service Target Service Probe Match
  • 23. WS – Discovery Service Closed Client Target Service Client Client Target Service Target Service By
  • 24. Multicast, Broadcast & Unicast Multicast Broadcast Unicast
  • 25. WCF With Discovery Server Side Normal endpoints with EndpointDiscoveryBehavior Discovery endpoint with ServiceDiscoveryBehavior Target Service
  • 26. WCF With Discovery Server Side < system.serviceModel > < service name =&quot;HelloService&quot;> < endpoint address = &quot;net.tcp://localhost/&quot; binding = &quot;netTcpBinding&quot; contract = &quot;ICalculator&quot; />      < endpoint kind = &quot; udpDiscoveryEndpoint &quot; /> </ service >   </ behaviors > < serviceBehaviors > < behavior > < serviceDiscovery /> </ behavior > </ serviceBehaviors > </ behaviors > </ system.serviceModel >
  • 27. Create discovery client Define the search Criteria for the client Choose endpoint, from the search result. WCF With Discovery Client Side ( Two steps ) var client = new DiscoveryClient ( new UdpDiscoveryEndpoint () ); var criteria = new FindCriteria ( typeof ( ICalculatorService ) ); FindResponse findResponse = client.Find( criteria ); var address = findResponse.Endpoints[0].Address Binding? ListenUri? Scope?
  • 29. How to Know About The Binding? Add MEX endpoint Discovery the MEX endpoint Use the MetadataResolver to resolve the binding. ServiceEndpointCollection endpoints = MetadataResolver .Resolve( typeof ( IHelloService ), mexAddress );
  • 30. Dynamic Endpoint DiscoveryClientBindingElement is added to the binding you specify in the DynamicEndpoint constructor, if not already present. var dynamicEndpoint = new DynamicEndpoint ( ContractDescription .GetContract( typeof ( ICalc ) ), new NetTcpBinding () ); dynamicEndpoint.FindCriteria.Scopes.Add(...); var client = new CalcClient ( dynamicEndpoint );
  • 32. Discovery Announcements < service name =&quot;HelloService&quot;>      ...      < endpoint name =&quot;udpDiscovery“ kind =&quot;udpDiscoveryEndpoint&quot;/> </ service > ... < serviceBehaviors >    < behavior >       < serviceDiscovery >          < announcementEndpoints >             < endpoint name = &quot; udpAnnouncement &quot; kind = &quot; udpAnnouncementEndpoint &quot; />             </ announcementEndpoints >          </ serviceDiscovery >    </ behavior > </ serviceBehaviors >  Server Side:
  • 33. Discovery Announcements var announcementService = new AnnouncementService (); announcementService.OnlineAnnouncementReceived += OnOnlineEvent; announcementService.OfflineAnnouncementReceived += OnOfflineEvent; using ( var host = new ServiceHost ( announcementService ) ) { host.AddServiceEndpoint( new UdpAnnouncementEndpoint () ); host.Open(); ... } Consumers Side:
  • 36. Discovery Proxy Managed discovery allows you to locate services no matter where they are, as long as they are registered with a discovery proxy. Client Target Service Client Client Target Service Target Service Discovery Proxy Hello
  • 37. Discovery Proxy Managed discovery allows you to locate services no matter where they are, as long as they are registered with a discovery proxy. Client Target Service Client Client Target Service Target Service Discovery Proxy Probe
  • 38. Discovery Proxy Managed discovery allows you to locate services no matter where they are, as long as they are registered with a discovery proxy. Client Target Service Client Client Target Service Target Service Discovery Proxy Probe Match
  • 39. Discovery Proxy Managed discovery allows you to locate services no matter where they are, as long as they are registered with a discovery proxy. Client Target Service Client Client Target Service Target Service Discovery Proxy By
  • 41. Service Discovery When service is open he send to MDC a message ( Endpoint info). When Service look for a service he ask the MDC. Unified Cache View
  • 42. Solution Advantage No need to do multicast communication The server endpoints info is available to all the services immediate after the server is open, ( no need to do communication ). When the service is unavailable (down time) the endpoint info will still be available
  • 44. Why a Router Service? Load balancing Priority routing to application pools or servers according to message content. Partitioning services so that messages targeting operations can be handled by different application pools or servers.
  • 45. Router Service Architecture Server C Server C Server B Client Router Service Filter Tables Filters Service A Service B Service C
  • 46. Router Endpoints & Contracts < service name = &quot; System.ServiceModel.Routing.RoutingService &quot; >    < endpoint name = &quot;reqReplyEndpoint &quot; address = &quot;&quot; binding = &quot; basicHttpBinding &quot; contract = &quot; System.ServiceModel.Routing.IRequestReplyRouter &quot; /> </ service >
  • 47. Configuring Filters The RouterService evaluates filters to determine how to forward the message. < serviceBehaviors > < behavior > < routing filterTableName = &quot; MyRoutingTable &quot; /> </ behavior > </ serviceBehaviors > < routing > < filters > < filter name =&quot;MatchAllFilter1&quot; filterType =&quot;MatchAll&quot; /> </ filters > < filterTables > < filterTable name =&quot;MyroutingTable&quot;> < add filterName =&quot;MatchAllFilter1&quot; endpointName =&quot;CalculatorService&quot; /> </ filterTable > </ filterTables > </ routing > < client > < endpoint name =&quot;CalculatorService&quot; address =&quot;http://...&quot; binding =&quot;basicHtttpBinding&quot; contract =&quot;*&quot; > </ client >
  • 48. Message Filter Compares the &quot;To&quot; & Headers address to the endpoint address Compares the incoming &quot;Action&quot; value against the actions on the contract
  • 49. Message Filter Compares the &quot;To&quot; & Headers address to the endpoint address Compares the incoming &quot;Action&quot; value against the actions on the contract < filters > < filter name =&quot;addFilter&quot; filterType =&quot;XPath&quot;   filterData =&quot;...&quot; > < filter name =&quot;addFilter&quot; filterType =&quot;Action&quot;  filterData =&quot;...&quot; > </ filters >
  • 51. Binding Configuration The router typically does not process protocol headers passed by the client. Security Reliable sessions Transactions Other related protocols.
  • 53. Error Handing You can define different lists of alternate endpoints that will be used if communicating with the initial target endpoint results in an error. < routing > ... < filterTable name =&quot;MyroutingTable&quot;> < add filterName =&quot;f1&quot; endpointName =&quot;t1&quot; backupList =&quot;altEndpoints&quot; /> </ filterTable > ... < backupLists >         < backupList name =&quot;altEndpoints&quot;>             < add endpointName =&quot;CalculatorService2&quot;/>                   </ backupList >       </ backupLists > </ routing >
  • 54. Multicast Routing Behavior Supports automatically routing a particular incoming message to multiple destinations in a “multicast” fashion. < routing > < filters > < filter name =&quot;Filter1&quot; filterType =&quot;MatchAll&quot; /> </ filters > < filterTables > < filterTable name =&quot;MyroutingTable&quot;> < add filterName =&quot;Filter1&quot; endpointName =&quot;Target1&quot; /> < add filterName =&quot;Filter1&quot; endpointName =&quot;Target2&quot; /> < add filterName =&quot;Filter1&quot; endpointName =&quot;Target3&quot; /> </ filterTable > </ filterTables > </ routing > “ Multicast”
  • 55. Higher Default Throttling Settings MaxConcurrent Sessions 10  100 * CPU MaxConcurrent Calls 16  16 * CPU MaxConcurrent Instances 26  116 * CPU
  • 57. Serialization Improvements public UserInfo EchoUser ( int userId ); Encoding Deserialization Serialization Encoding Binding Transport
  • 58. KnownType Attribute Make sure a type is included in the serialization stream [ ServieContract ] public intrface IMedia { [ OperationContract ] Media GetMedia( Media media ); } [ DataContract ] public class Media { ... } [ DataContract ] public class DVD : Media { ... } [ DataContract ] public class CD : Media { ... } < Envelope > < Header > < Action >E4D/IMedia/GetMedia</ Action > </ Header > < Body > < GetMedia > < media > < Name>Madona </ Name > < Type>CDWR </ Type > </ media > </ GetMedia > </ Body > </ Envelope >
  • 59. [ ServieContract ] public intrface IMedia { [ OperationContract ] Media GetMedia( Media media ); } [ DataContract ] public class Media { ... } [ DataContract ] public class DVD : Media { ... } [ DataContract ] public class CD : Media { ... } < Envelope > < Header > < Action >E4D/IMedia/GetMedia</ Action > </ Header > < Body > < GetMedia > < media type =&quot;CD&quot;> < Name>Madona </ Name > < Type>CDWR </ Type > </ media > </ GetMedia > </ Body > </ Envelope >
  • 60. KnownType Attribute Make sure a type is included in the serialization stream [ ServieContract ] public intrface IMedia { [ OperationContract ] Media GetMedia( Media media ); } [ DataContract ] [ KnownType ( typeof ( DVD ) )] [ KnownType ( typeof ( CD ) ) ] public class Media { ... } [ DataContract ] public class DVD : Media { ... } [ DataContract ] public class CD : Media { ... } < Envelope > < Header > < Action >E4D/IMedia/GetMedia</ Action > </ Header > < Body > < GetMedia > < media type =&quot;CD&quot;> < Name>Madona </ Name > < Type>CDWR </ Type > </ media > </ GetMedia > </ Body > </ Envelope > Known Type
  • 63. Data Contract Resolver New types can be added at runtime using the xsi:type schema declarations. The ResolveType method is invoked only during serialization and is used to map any type to a new xsi:type name. The ResolveName method is used only during deserialization and allows you to map any xsi:type information to a type.
  • 66. Enhanced REST Support Caching support in IIS/WAS Dynamic content types Improved exception support JSONP support for AJAX Services Automatically generated help page ASP.NET Routing integration Helper methods for creating content
  • 67. Help Page < behaviors > < endpointBehaviors > < behavior name = &quot; HelpBehavior &quot; > < webHttp enableHelp = &quot; true &quot; /> </ behavior > </ endpointBehaviors > </ behaviors >
  • 68. Caching < system.web > < caching > < outputCacheSettings > < outputCacheProfiles > < add name = &quot; CacheFor60Seconds &quot; duration = &quot; 60 &quot; varyByParam = &quot; format &quot; /> </ outputCacheProfiles > </ outputCacheSettings > </ caching > </ system.web > [ AspNetCacheProfile (&quot; CacheFor60Seconds &quot;)] [ WebGet ] [ OperationContract ] public Counter GetItem(){...}
  • 70. JSONP For AJAX Services Convention used to invoke cross-domain scripts by generating script tags in the current document. Result is returned in a specified callback function <script src=&quot;http://...&quot;> can evaluate scripts from any domain. < serviceHostingEnvironment aspNetCompatibilityEnabled =&quot;true&quot;/> < standardEndpoints > < webScriptEndpoint > < standardEndpoint crossDomainScriptAccessEnabled =&quot;true&quot;/> </ webScriptEndpoint > </ standardEndpoints >
  • 71. JSONP
  • 72. Dynamic Content WCF can automatically create response format based on Content-Type and Accepts headers. Helper methods for creating content Available through WebOperationContext public Message CreateAtom10Response(...); public Message CreateJsonResponse<T>(...); public Message CreateStreamResponse(...); public Message CreateTextResponse(...); public Message CreateXmlResponse(...); public Message CreateXmlResponse<T>(...);
  • 74. Resources http://blogs.microsoft.co.il/blogs/vardi/ A Developer’s Introduction to WCF 4 Beta 1 Service Configuration Improvements in .NET 4 What’s New in WCF 4.0? Jesus Rodriguez's WebLog