• Save
WCF 4.0
Upcoming SlideShare
Loading in...5
×
 

WCF 4.0

on

  • 3,680 views

What's new in WCF 4.0

What's new in WCF 4.0

Statistics

Views

Total Views
3,680
Views on SlideShare
3,647
Embed Views
33

Actions

Likes
7
Downloads
0
Comments
0

5 Embeds 33

http://www.slideshare.net 21
http://www.linkedin.com 8
http://www.lmodules.com 2
http://translate.googleusercontent.com 1
http://www.codeproject.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    WCF 4.0 WCF 4.0 Presentation Transcript

    • 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