Running Around GENED Proxyless in the Wild - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

Running Around GENED Proxyless in the Wild

Description:

What ointment will sooth this WCF proxy ailment? ... This is the 'hustle and flow' class of the solution; it does all the work. ... – PowerPoint PPT presentation

Number of Views:66
Avg rating:3.0/5.0
Slides: 23
Provided by: danielbu
Category:

less

Transcript and Presenter's Notes

Title: Running Around GENED Proxyless in the Wild


1
Running Around (GEN-ED) Proxy-less in the Wild
  • Daniel Bullington
  • Senior Software Engineer
  • SnagAJob.com, Inc.
  • -- and --
  • Creator of Software Is Hardwork Library and Blog

2
Orders of the Day
  • Answers to these questions
  • What are WCF proxies?
  • What are the typical WCF proxy scenarios?
  • Why do WCF proxies cause burning and itching?
  • What ointment will sooth this WCF proxy ailment?
  • What are the effects/unknowns of this new salve?
  • Or your money back 100 of 0 0.

3
Hello, My Name is WCF Proxy
  • WCF proxies allow for communication from a client
    to a service, in terms of a service contract
    interface, without having to work with the
    underlying plumbing code.
  • WCF provides a vertical programming model. You
    get the same rich programming features on the
    client side as that you get on the service-side.
    1
  • Internally a WCF proxy is a .NET Remoting
    transparent proxy which is wrapped inside the
    type System.ServiceModel.Channels.ServiceChannel.
    1
  • The transparent proxy let you operate on an
    object in terms of a service contract, but the
    WCF runtime is actually intercepting these calls
    and doing the heavy lifting.

4
The Magical WCF Proxy Fairy
  • There are two ways to acquire a WCF proxy
  • A class that is a derivation of ClientBase1 and
    an implementation of a service contract, which
    forwards implementation calls to
    ClientBase1.Channel.
  • Manually created
  • SvcUtil.exe generated (THIS IS HOW WE DO)
  • An instance of ChannelFactory1 and a call to
    ChannelFactory1.CreateChannel()
  • Returns an implementation of a service contract

5
WCF Proxy Symptoms of Infection
  • In our current code base, our WCF proxies cause
    us many headaches.
  • Since we generate our proxies, we have management
    of code, versioning and staging of changes,
    duplication of classes in differing namespaces
    and/or assemblies, and other issues with type
    fidelity.
  • Our usage of Spring.NET IDisposable
    implementing (generated) WCF proxies do not clean
    up (Abort()) after themselves either, when a
    fault on the communication channel occurs.

6
The Cure is Worse Than the Disease
  • We could leverage SvcUtil.exe in smarter ways by
    tweaking command line parameters. Still not ideal
    on many number of criteria.
  • We could hand roll (or generate) better
    ClientBase1 implementations. This suffers still
    from some ailments such as level of effort.
  • We could leverage shared service and data
    contracts, with raw ChannelFactory1 usages. This
    is A LOT better but falls short on a key issue
    which needs addressing correct lifetime
    management of the WCF proxy. This IS a good
    starting point

7
IntroducingSoftwareIsHardwork.ServiceModelClient
  • After discussing the problem with Kevin Hazzard,
    Todd King, et. al. I took a stab at it in free
    time. My idea was to proxy the proxy (PxPx)
    using a .NET remoting real proxy, intercept the
    method calls on a given service contact, do some
    stuff, forward the call to a real WCF proxy, do
    some more stuff, then return the result (if not a
    System.Void call).
  • Same proven approach I use for SoftwareIsHardwork.
    Database.Contracts to execute strongly typed
    stored procedures from C.
  • Part of my open source code library
    (SoftwareIsHardwork).

8
Design (? Wow!)
  • The main design goal was to have a usage scenario
    similar to the following
  • Also, the internal implementation had to support
    caching, cleanup, and performance.

9
10,000 Mile API Overview
10
IServiceClientFactory
  • The main entry point to acquire a PxPx via
    CreateInstance1().
  • An implementation should allow creation of a
    single PxPx instance in terms of a
    TServiceContract.
  • Implementations may decide to register created
    objects for a callback when the factory is
    disposed
  • The PxPx could lifetime dependson the factory
    lifetime.

11
RealProxyServiceClientFactory
  • Implements IServiceClientFactory provides PxPx
    instances via the use of ServiceClientRealProxy1.
  • Manages caching and reuse of instances
  • One PxPx for a given service contract type and
    endpoint configuration combination.
  • When disposed, calls disposeon all registered
    SCRP1 instancesand clears the cache
    non-reusable.

12
ServiceClientRealProxy1
  • A derviation of System.Runtime.Remoting.Proxies.Re
    alProxy.
  • Provides the mechanism to intercept calls on a
    service contract to make cool hallucinations.
  • You service contract method calls actually end up
    in the overriden IMessage Invoke(IMessage msg)
    method.
  • Some housekeeping is performed and the dynamic
    call is evaluated by the ServiceProxy class in
    terms of IInvokeDynamic.

13
IInvokeDynamic
  • Simple interface describing a dynamic method
    invocation.
  • object InvokeOperation(Type proxyType, MemberInfo
    memberInfo, object inputParameters, out
    object outputParameters)

14
ServiceProxy
  • This is the hustle and flow class of the
    solution it does all the work. It is a
    decoupling of the dynamic execution of a service
    method and such from the remoting real proxy
    infrastructure.
  • This decoupling allows for replacement strategies
    if, for some reason, real proxies were not
    adequate for a scenario.

15
Demo
  • Wow, I actually have some code to show

16
Lets Talk About Secs.
  • Performance is critical in our systems.
  • The implementation uses caching to drastically
    speed up usage a naïve implementation which
    would simply create and close a channel factory
    and/or channel per operation will NOT scale. More
    in a bitbut first, lets do the numbers (a loop
    of 1000 calls)
  • So yes, there is a few CPU cycles penalty.
  • 0.0001 sec. penalty per call on average

17
You Say ChannelFactoryltTgtI Say ChannelFactory1
  • Why so much caching?
  • Creating/disposing ChannelFactory is expensive
    1
  • Constructing the ContractDescription tree
  • Reflecting all of the required CLR types
  • Constructing the channel stack
  • Disposing all of the resources
  • ClientBase1 caches too, just differently.

18
ClientBase1 (Anti)Caching Strateg(ies)
  • Combination 1
  • callbackInstance
  • endpointConfigurationName
  • remoteAddress
  • Disabling (instantiation) 1
  • endpoint
  • Disabling (preemptive) 1
  • When any of these properties of ClientBaseltTgt is
    accessed before the inner channel is created and
    when ClientBaseltTgt.Open is called, the caching is
    disabled for this proxy.
  • ChannelFactory
  • Endpoint
  • ClientCredentials
  • Binding

19
Getting Off the Junk
  • Transition could be seamless the Spring.NET
    injection strategy
  • See Spring.NET Topic 5.2.4.3
  • Object creation via an instance factory method
    2
  • Instead of injecting a concrete proxy in config,
    we inject a PxPx from a page scoped
    IServiceClientFactory instance.
  • Need to dump all service (and operation), data,
    fault, and employment contracts into lib, remove
    all generated proxy artifacts, switch references
    across the board.

20
Ointment Side Effects, Contraindications, and
Unknowns
  • QA would need to test across the board.
  • Load balancing NetTcpBinding Channel caching
    (Eric)?
  • Channel ltgt Socket Lifetime
  • Align caching strategy more closely to .NET.
  • Need to bulk up test suite.
  • Start a 12-step program for Proxy Addicts

21
Conclusion
  • This could be the basis for our transition away
    from generated proxies.
  • This would save time and headaches.
  • This is really cool.
  • To quote Kevin Hazzard, the proxies are just
    there

22
Off Label
  • References
  • 1 Wenlong Dong http//blogs.msdn.com/wenlong
  • 2 http//www.springframework.net/docs/1.1.2/refe
    rence/html/objects.htmlobjects-creation-generic-t
    ypes
  • Source Code
  • http//www.codeplex.com/softwareishardwork
  • Blog
  • http//blog. softwareishardwork.com
  • SnagAJob.com
  • http//www.snagajob.com
Write a Comment
User Comments (0)
About PowerShow.com