1 / 41

WCF4: What's new?

WCF4: What's new?. Christian Weyer t hinktecture christian.weyer@thinktecture.com Session Code: INT302. Level 200. and Christian Weyer. Support & consulting for Windows and .NET software developers and architects (we are based in Germany) Developer coaching and mentoring

fabiano
Télécharger la présentation

WCF4: What's new?

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. WCF4: What's new? Christian Weyer thinktecturechristian.weyer@thinktecture.com Session Code: INT302 Level 200

  2. and Christian Weyer • Support & consulting for Windows and .NET software developers and architects (we are based in Germany) • Developer coaching and mentoring • Architecture consulting and prototyping • Architecture and code reviews • Applicationoptimization, troubleshooting, debugging • Focus on distributed applications, service orientation, workflows, cloud computing, interoperability, security, end-to-end solutions • Windows Server, WCF, WF, MSMQ, .NET Services, Windows Azure • http://www.thinktecture.com • christian.weyer@thinktecture.com

  3. Agenda • Config & Hosting • Discovery • Routing • REST • This & that • Not in Scope: Workflow Services

  4. Theme: "Help! WCF4 to the rescue…!?" • 4 major topics • What is not so good in WCF 3.x? • What could WCF4 do better? • Show it to me!

  5. Help! WCF4 to the rescue… "My service config files look more complicated than my service code!"

  6. Source: http://www.flickr.com/photos/liboni/2061335442 • WCF4Simplified Configuration

  7. New Feature #1:Config & Hosting • No need for <service> tag to configure a service • Configuration of default bindings and behaviors • Re-usable system-provided endpoint configurations, aka standard endpoints • Support for .svc-less activation

  8. Config & Hosting: Default Endpoints • Simplifiedconfigurationfordefaultscenarios ServiceHost serviceHost = new ServiceHost(typeof(HelloService),new Uri("http://localhost:7777/Services/Hello"), new Uri("net.tcp://localhost:7778/Services/Hello"));serviceHost.Open();Console.WriteLine("WCF Service isrunning.");Console.WriteLine("Press <ENTER> toterminateservice.");Console.ReadLine();serviceHost.Close(); … <configuration></configuration> 8

  9. Config & Hosting: Default Endpoints • Default endpoint behavior only kicks in when service has not been configured with any endpoints • Call host.AddDefaultEndpoints() to add set of default endpoints

  10. Config & Hosting: Default Bindings Definestandardsettingsfordefaultbindings <system.serviceModel>    <bindings>      <basicHttpBinding><bindingmaxReceivedMessageSize="9999999">          <readerQuotasmaxArrayLength="9999999"/>        </binding>      </basicHttpBinding>          </bindings>  </system.serviceModel> No nameattribute 10

  11. Config & Hosting: Default Behaviors Definestandardsettingsforbehaviors   <system.serviceModel>     <behaviors>      <serviceBehaviors><behavior>          <serviceMetadata httpGetEnabled="true"/>        </behavior>      </serviceBehaviors>    </behaviors>       </system.serviceModel> No nameattribute 11

  12. Config & Hosting: Protocol Mappings Can redefinedefaultprotocolmappingsforbindingsfor global use Pre-configureddefaultbindings <protocolMapping>  <addscheme="http" binding="basicHttpBinding"/>  <addscheme="net.tcp" binding="netTcpBinding"/>  <addscheme="net.pipe" binding="netNamedPipeBinding"/>  <addscheme="net.msmq" binding="netMsmqBinding"/></protocolMapping> 12

  13. Config & Hosting: Protocol Mappings Add orreplaceyourownprotocolmappingconfiguration <protocolMapping>  <clearscheme="http" /><addscheme="http" binding="customBinding"bindingConfiguration="binaryHttp" /></protocolMapping><bindings> <customBinding>    <bindingname="binaryHttp">      <binaryMessageEncoding/>      <httpTransport/>    </binding>  </customBinding></bindings> 13

  14. Config & Hosting: Standard Endpoints • Reusable pre-configured system endpoints • endpoints in WCF have many moving parts (address, binding, contract, behaviors) • in some cases some of these parts are constrained • most common with infrastructure or system endpoints where the contract is fixed and provided externally to the service • Specify a standard endpoint by using kind attribute <system.serviceModel>    <services>        <servicename="HelloService"><endpointkind="udpDiscoveryEndpoint" />        </service>    </services>    …</system.serviceModel> 14

  15. .svc-lessActivation • No longer need to have a physical .svc file for each service • specify activation path in web.config <system.serviceModel>    <serviceHostingEnvironment>            <serviceActivations>        <addrelativeAddress="/Hello.svc" service="HelloService"/>      </serviceActivations>    </serviceHostingEnvironment>    <services>      <servicename="HelloService">        <endpointbinding="webHttpBinding"contract="IHelloService" />              </service>    </services>[...] 15

  16. Help! WCF4 to the rescue… "I need to provide one single endpoint to my clients, but support multiple services (in multiple versions)!"

  17. Source: http://ciscorouting.com/routing_engine.jpg • WCF4RoutingService

  18. New Feature #2: Routing • Intermediate Routing Pattern is a well understood pattern in enterprise architecture • just one service entry point with a universal contract • route incoming messages to the appropriate business services • use it to determine path of a message within a system • there can be a cascade of routers each responsible for different aspects of routing messages • WCF 4 now provides a SOAP-based RoutingService • routes, tables, and filters configurable

  19. Routing: Sample Architecture Service A Binding/protocol Y Binding/protocol X Router Service Consumer Service B Tables Filters Service C config Binding/protocol Z

  20. Routing Host RoutingService in any WCF host Useroutingtablesandfilterstoconfigureroutingrules <client>      <endpoint name="HelloService" address="http://..." binding="basicHttpBinding" contract="*" /></client> <routing> <filters> <filter name="MatchAllFilter" filterType="MatchAll" /> </filters> <filterTables> <filterTablename="mainRoutingTable"> <addfilterName="MatchAllFilter" endpointName="HelloService" /> </filterTable> </routingTables> </routing> 20

  21. Help! WCF4 to the rescue… "ABC?My client applications should just know about the contract, nothing more!"

  22. Source: http://www.flickr.com/photos/97705796@N00/3577907718 • WCF4Discovery

  23. New Feature #3 :Discovery • WS-Discovery as standard discovery mechanism • e.g. printer can use WS-Discovery to announce presence on a network • can be discovered by different applications that require printing documents • Windows Vista's (and up) contact location feature • WCF services can be made discoverable • on a local subnet ad-hoc (using WS-Discovery over UDP) • on larger managed networks (using WS-Discovery proxy) • WCF clients can discover services on a local subnet or a larger managed networks

  24. Discovery: Ad-Hoc Service config: <system.serviceModel>      <services>        <servicename="HelloService"behaviorConfiguration="serviceBehavior">          <host>            <baseAddresses>              <addbaseAddress="http://localhost:7777/Services/Hello"/>            </baseAddresses>          </host>          <endpointbinding="basicHttpBinding"contract="IHelloService" />          <endpointname="udpDiscovery" kind="udpDiscoveryEndpoint"/>        </service>      </services>      <behaviors>        <serviceBehaviors>          <behaviorname="serviceBehavior">            <serviceDiscovery />          </behavior>        </serviceBehaviors>              </behaviors></system.serviceModel> 24

  25. Discovery: Ad-Hoc Client code: DiscoveryClientdiscoveryClient = newDiscoveryClient("udpDiscoveryEndpoint");FindCriteriafindCriteria = newFindCriteria(typeof(IHelloService));FindResponsefindResponse = discoveryClient.Find(findCriteria);if (findResponse.Endpoints.Count > 0){EndpointAddressaddress = findResponse.Endpoints[0].Address; ChannelFactory<IHelloServiceChannel> factory = newChannelFactory<IHelloServiceChannel>(newBasicHttpBinding(), address);IHelloServiceChannelclient = newfactory.CreateChannel();client.SayIt("Hellofrom WCF4!");client.Close();factory.Close();} 25

  26. Discovery: Probes & Announcements Discovery Client Discovery Client Probe Announcements (Hello / Goodbye) Service A Service B Service A Service B

  27. Discovery: Announcements Service config: UseAnnouncementService API on consumingsidetosubscribetoevents Can usethisapproachtobuildservice-orientedpeersolutions <behaviors>    <serviceBehaviors>       <behaviorname="serviceBehavior">          <serviceDiscovery>            <announcementEndpoints>              <endpointname="udpAnnouncement" kind="udpAnnouncementEndpoint"/>            </announcementEndpoints>          </serviceDiscovery>       </behavior>    </serviceBehaviors>      </behaviors> 27

  28. Help! WCF4 to the rescue… "Give me a little bit more REST-fulness in WCF!"

  29. Source: http://www.annisonne.de/resources/bild18.jpg • WCF4REST Support

  30. New Feature #4: Enhanced REST Support • Caching support in IIS/WAS • ASP.NET Routing integration • Dynamic content types • Helper methods for creating content • Improved exception support • JSONP support for AJAX Services • Automatically generated help page "

  31. Dynamic Content • Dynamic content types are now supported • based on Content-Type and Accepts headers • WCF can automatically create response format • Developer can decide to opt-in manually • 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>(...); "

  32. JSONP for AJAX-enabled Services • JSON withPadding • 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="http://...">can evaluate scripts from any domain • script retrieved by those tags is evaluated within a scope in which other functions may already be defined <system.serviceModel> <serviceHostingEnvironmentaspNetCompatibilityEnabled="true"/> <standardEndpoints> <webScriptEndpoint> <standardEndpointcrossDomainScriptAccessEnabled="true"/> </webScriptEndpoint> </standardEndpoints> </system.serviceModel> 32

  33. This & That Small, but good things

  34. Source: http://www.flickr.com/photos/25750231@N07/2943443607 • WCF4Miscellaneous

  35. New Feature #X: This & that: Throttles • Controlling resource usage on the service side through throttling • .NET 3.5 SP1 (different settings before) • MaxConcurrentSessions: default is 10 • MaxConcurrentCalls: default is 16 • MaxConcurrentInstances: default is 26 • .NET 4.0 • MaxConcurrentSessions: default is 100 * processor count • MaxConcurrentCalls: default is 16 * processor count • MaxConcurrentInstances: default is MaxConcurrentSessions + MaxConcurrentCalls

  36. This & that: Even More • Non-destructive queue receive • adds "peek / lock“ mechanism to WCF MSMQ channel • ETW tracing integration • Metadata • new behavior allowing to modify returned metadata XML to fix-up URLs based on incoming request's host header/port • WS-I Basic Profile 1.2 • supports WS-Addressing and MTOM • Compression • support for automatic response decompression over HTTP (e.g. with IIS) • DataContractSerializer enhancements • Numerous fixes

  37. Resources • Christian Weyer‘sblogpostsfor WCF 4.0 Beta 1 • Simplified configuration – or: “Look ma: my config shrinks!” • http://blogs.thinktecture.com/cweyer/archive/2009/05/07/415326.aspx • .svc-less Activation – or: “Look ma: my [REST] URLs look good!” • http://blogs.thinktecture.com/cweyer/archive/2009/05/08/415327.aspx • Dynamic service and endpoint discovery – or: “Look ma: I just need the contract to talk to my service!” • http://blogs.thinktecture.com/cweyer/archive/2009/05/08/415329.aspx

  38. Resources • Standard endpoints – or: “Look ma: streamlined infrastructure and system endpoints!” • http://blogs.thinktecture.com/cweyer/archive/2009/05/08/415330.aspx • Discovery announcements – or: “Look ma: I can see when my service goes online or offline!” • http://blogs.thinktecture.com/cweyer/archive/2009/05/08/415332.aspx • Routing Service – or: “Look ma: Just one service to talk to!” • http://blogs.thinktecture.com/cweyer/archive/2009/05/08/415335.aspx • Protocol bridging & fault tolerance with the Routing Service – or: “Look ma: Really just one service to talk to!” • http://blogs.thinktecture.com/cweyer/archive/2009/05/08/415341.aspx

  39. Resources • Email Christian Weyer • christian.weyer@thinktecture.com • Weblog Christian Weyer • http://blogs.thinktecture.com/cweyer • thinktecture • http://www.thinktecture.com

  40. Summary • WCF is still… WCF! • ABC is still there • No bigchanges, but furtherinvestmentintothefoundation • smallerstepsthancomparedtootherareas in .NET Framework, e.g. WF4 • Discovery canbeinterestingespeciallyforenterprisescenarios • Routing oftenneeded in morecomplexarchitectures • A bitmore REST-fulness

  41. Required Slide © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

More Related