Your SlideShare is downloading. ×
WCF 4.0
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

WCF 4.0

2,845
views

Published on

What's new in WCF 4.0

What's new in WCF 4.0

Published in: Technology

0 Comments
8 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,845
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
8
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 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
  • 3. Simplified Configuration
  • 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
  • 6. Default Endpoint In WEB
  • 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 >
  • 10. Simplified Configuration
  • 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 >
  • 12. File-less Activation
  • 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 >
  • 16. Standard Endpoint
  • 17. Service Discovery
  • 18. Why We Need Discovery?
  • 19. Async WCF Services
  • 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?
  • 28. Basic Discovery
  • 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 );
  • 31. Dynamic Endpoint
  • 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:
  • 34. Discovery Announcements
  • 35. Announcement Data
  • 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
  • 40. Discovery Proxy
  • 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
  • 43. Routing Services
  • 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 >
  • 50. Filtering architecture
  • 51. Binding Configuration
    • The router typically does not process protocol headers passed by the client.
      • Security
      • Reliable sessions
      • Transactions
      • Other related protocols.
  • 52. Routing Services
  • 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
  • 56. Serialization Improvements
  • 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
  • 61. The Serialization in WCF 3.5
  • 62. The Serialization in WCF 4.0
  • 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.
  • 64. Data Contract Resolver
  • 65. Web Http Programming
  • 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(){...}
  • 69. Help Page
  • 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>(...);
  • 73. Dynamic Content
  • 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