What’s Next?

Since service-oriented frameworks provide off-the-shelf plumbing for connecting services together, the more granular those services are, the more use the application can make of this infrastructure, and the less plumbing the developers have to write. Taken to the ultimate conclusion, every class and primitive should be a service, to maximize the use of the ready-made plumbing and to avoid handcrafting plumbing. This, in theory, will enable effortlessly transactional integers, secure strings, and reliable classes. But in practice, is that viable? Can .NET support it? Will future platforms offer this option?

I believe that as time goes by and service-oriented technologies evolve, the industry will see the service boundary pushed further and further inward, making services more and more granular, until the most primitive building blocks will be services. This would be in line with the historical trend of trading performance for productivity via methodology and abstraction. As an industry, we have always traded performance for productivity. .NET, where every class is treated as a binary component, is slower than COM, but the productivity benefit justifies this. COM itself is orders of magnitude slower than C++, yet developers opted for COM to address the problems of object orientation. C++ is likewise slower than C, but it did offer the crucial abstractions of objects over functions. C in turn is a lot slower than raw assembly language, but the productivity gains it offered more than made up for that.

My benchmarks show that WCF can easily sustain hundreds of calls per second per class, making it adequate for the vast majority of business applications. While of course there is a performance hit for doing so, the productivity gains more than compensate, and historically, it is evident that this is a trade-off you should make. WCF does have detrimental overhead, but it’s to do with ownership, not performance (which is adequate). Imagine a decent-sized application with a few hundred classes, each of which you wish to treat as a service. What would the Main() method of such an application look like, with hundreds of service host instances to be instantiated, opened, and closed? Such a Main() method would be unmaintainable. Similarly, would a config file with many hundreds of service and client endpoint declarations be workable?

The truth is that in practical terms, WCF cannot support (out of the box) such large-scale granular use. It is designed to be used between applications and across layers in the same application, not in every class. Just as COM had to use C++ and Windows, WCF is bolted on top of .NET. The language used (C# or Visual Basic) is merely component-oriented, not service-oriented, and the platform (.NET) is component-oriented, not service-oriented. What is required is a service-oriented platform, where the basic constructs are not classes but services. The syntax may still define a class, but it will be a service, just as every class in .NET is a binary component, very different from a C++ class. The service-oriented platform will support a config-less metadata repository, much like .NET generalized the type library and IDL concepts of COM. In this regard, WCF is merely a stopgap, a bridging technology between the world of components and the world of service (much like ATL once bridged the world of objects and C++ with the world of components, until .NET stepped in to provide native support for components at the class and primitive level).

A Service-Oriented Platform

If you take a wider view, every new idea in software engineering is implemented in three waves: first there is the methodology, then the technology, then the platform.

For example, object orientation as a methodology originated in the late ’70s. The top C developers at the time did develop object-oriented applications, but this required manually passing state handles between functions and managing tables of function pointers for inheritance. Clearly, such practices required a level of conviction and skills that only very few had. With the advent of C++ in the early ’80s came the technology, allowing every developer to write object-oriented applications. But C++ on its own was sterile, and required class libraries. Many developers wrote their own, which of course was not productive or scalable. The development of frameworks such as MFC as an object-oriented platform, with types ranging from strings to windows, is what liberated C++ and enabled it to take off.

Similarly, take component orientation: in the first half of the ’90s, developers who wanted to use COM had to write class factories and implement IUnknown, and concoct registry scripts and DLL entries. As a methodology, COM was just inaccessible. Then ATL came along, and this technology enabled developers to expose mere C++ classes as binary components. But the programming model was still too complex, since Windows knew nothing about COM, and the language was still object-oriented, lacking support for basic constructs such as interfaces. .NET as a component-oriented runtime provided the missing platform support for components at the class, primitive, language, and class library level.

Service orientation emerged as a methodology in the early 2000s, but at the time it was practically impossible to execute. With WCF, developers can expose mere classes as services, but the ownership overhead prevents widespread and granular use. I do not have a crystal ball, but I see no reason why the waves of methodology/technology/platform should stop now. Extrapolating from the last 30 to 40 years of software engineering, we are clearly missing a service-oriented platform. I believe the next generation of technologies from Microsoft will provide just that.

Every class as a service

Until we have a service-oriented platform, must we suffer the consequences of either unacceptable ownership overhead (granular use of WCF) or productivity and quality penalties (handcrafted custom plumbing)?

Chapter 1 introduces my InProcFactory class, which lets you instantiate a service class over WCF:

public static class InProcFactory
{
   public static I CreateInstance<S,I>() where I : class
                                         where S : I;
   public static void CloseProxy<I>(I instance) where I : class;
   //More members
}

When using InProcFactory, you utilize WCF at the class level without ever resorting to explicitly managing the host or having client or service config files:

[ServiceContract]
interface IMyContract
{
   [OperationContract]
   string MyMethod();
}

class MyService : IMyContract
{...}

IMyContract proxy = InProcFactory.CreateInstance<MyService,IMyContract>();
proxy.MyMethod();
InProcFactory.CloseProxy(proxy);

This line:

IMyContract proxy = InProcFactory.CreateInstance<MyService,IMyContract>();

is syntactically equivalent to the C# way of instantiating a class type:

IMyContract proxy = new MyService();

The difference syntax-wise is that with C#, there is no need to specify the queried interfaces, since the compiler will examine the class, see if it supports the interface, and implicitly cast the class to the assigned interface variable. As it lacks compiler support for services, InProcFactory requires you to specify the required contract.

Note

Chapter 1 also shows my WcfWrapper helper class, which can eliminate even that difference, although at the price of defining a wrapper class.

However, the big difference between instantiating the class over WCF rather than C# is that when you do this all the powerful WCF features described in the rest of this book kick in: call timeout, encrypted calls, authentication, identity propagation, transaction propagation, transaction voting, instance management, error masking, channel faulting, fault isolation, buffering and throttling, data versioning tolerance, synchronization, synchronization context affinity, and more. With very little effort, you can also add tracing and logging, authorization, security audits, profiling and instrumentation, and durability, or intercept the calls and add many degrees of extensibility and customization.

InProcFactory lets you enjoy the benefits of WCF without suffering the ownership overhead. To me, InProcFactory is more than a useful utility—it is a glimpse of the future.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.27.45