1 / 23

Taking Control of WCF

Taking Control of WCF. Jay Hill Patrick Roeper. Presentation Goals. Take the most common WCF experience and make it better Leverage OO design principles; improve extensibility, maintainability , testability Reduce repetition Demonstrate techniques when playing role of: Publisher

marva
Download Presentation

Taking Control of WCF

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. Taking Control of WCF Jay Hill Patrick Roeper

  2. Presentation Goals • Take the most common WCF experience and make it better • Leverage OO design principles; improve extensibility, maintainability, testability • Reduce repetition • Demonstrate techniques when playing role of: • Publisher • Consumer • Publisher and Consumer

  3. Demo • Jay is recovering from star-trek-hand syndrome • Occasional accidental-reboot while typing

  4. MethodA(ReqA req) { Logger.Log(“Handling ReqA”); try { var result = new ResultA(); result.Name = GetName(req.Id); result.Email = GetEmail(req.Id); return result; } catch (Exception ex) { Logger.LogError(ex); throw; } } Horizontal API var result = new ResultA(); result.Name = GetName(req.Id); result.Email = GetEmail(req.Id); return result; return req.Role == GetRole(req.Id) ? new ResponseB(true) : new ResponseB(false); using(var db = new Ctx()) { return db.Contacts; } MethodB(ReqB req) { Logger.Log(“Handling ReqB”); try { return req.Role == GetRole(req.Id) ? new ResponseB(true) : new ResponseB(false); } catch (Exception ex) { Logger.LogError(ex); throw; } } MethodC(ReqC req) { Logger.Log(“Handling ReqC”); try { using(var db = new Ctx()) { return db.Contacts; } } catch (Exception ex) { Logger.LogError(ex); throw; } }

  5. Horizontal API var result = new ResultA(); result.Name = GetName(req.Id); result.Email = GetEmail(req.Id); return result; return req.Role == GetRole(req.Id) ? new ResponseB(true) : new ResponseB(false); using(var db = new Ctx()) { return db.Contacts; } Logging Caching Exception Handling

  6. What we don’t like • WCF services have many responsibilities; .svc file makes it hard to modularize operation handling • Generated client code is clunky and is a duplication of server-side contracts; easy to get out of sync • Client endpoints scale in parallel to server endpoints

  7. Step 1 – Modularizing Operations • Move to request/response • Re-imagine each operation’s code as a separate class – MessageHandler<> • One-to-One with request • Provide a hook into WCF internals that will instantiate and invoke a MessageHandler<> instead of a service instance (.svc) • Identify and isolate infrastructural concerns from MessageHandler<> implementations

  8. Demo

  9. Recap • Each operation is handled in its own class • Extensible • Maintainable • Testable .svc File Invoker Invoker Message Handler

  10. What we don’t like • WCF services have many responsibilities; .svc file makes it hard to modularize operation handling • Generated client code is clunky and is a duplication of server-side contracts; easy to get out of sync • Client endpoints scale in parallel to server endpoints

  11. Step 2 – Deploy an API • Goodbye “Add Service Reference” • Move service definition and data contract components to a separate assembly • Package a client wrapper for invoking a service with the contract assembly • Open doors to build integration between products

  12. Demo

  13. Recap • Contracts moved to separate assembly and shared with consumers (possibly through build integration) • Client API packaged with contracts • DRY – Single LOC invocation • KISS – Hide IDisposable from consumer

  14. Shared Contracts Server.sln Client.sln Contracts (Build) Contracts Server Logic Client Logic Web Host Client App

  15. What we don’t like • WCF services have many responsibilities; .svc file makes it hard to modularize operation handling • Generated client code is clunky and is a duplication of server-side contracts; easy to get out of sync • Client endpoints scale in parallel to server endpoints

  16. Authentication Client Authentication Service Financial Service Financial Client Search Service Search Client Administration Service Administration Client

  17. Step 3 – Create a single gateway • Create another service (“Portal”) with a single operation that will process any request • Uses the same invoker as all other services to call a MessageHandler for the request • Include a client API that will accept any request • Add “facilities” under the covers • Compression

  18. Demo

  19. Recap DB Authentication MH1 MH2 Customer MH3 MH4 … SOA Byte[] Portal …Request Byte[] N-Tier

  20. Nitpicker Corner • Async • Reuse requests for > 1 operations • Auditing vs. Tracing • Decorator vs. IErrorHandler • .Svc exception smell • Portal in distributed environment • Horizontal APIs enable discoverability

More Related