Anda di halaman 1dari 28

Christian Weyer | thinktecture

Jenseits von System.ServiceModel

WCF Tools und Libraries

Christian Weyer
Solution architect and principal consultant at thinktecture Focus on distributed applications service orientation, workflows cloud computing interoperability pragmatic end-to-end solutions
Windows Server, WCF, WF, MSMQ, Windows Azure platform

Microsoft MVP for Windows Azure (Architecture) Independent Microsoft Regional Director for Germany

Modeling contracts Development process Implementation strategies Configuration On the Wire Communication Under Load Misc

Modeling & Metadata

WCF is strong for interoperability scenarios (read: Web Services in the WS-* empire) Contract modeling can be important to succeed in interoperability Various approaches to improve the level of interoperability contract-first modeling flattening WSDL XSD and WSDL are the contracts in non-pure-WCF environments least common denominator

Schema-based Contract-First
Think in XSD and WSDL first Two basic steps design your contract's data, messages and interface generate code from the contract Tool support would be nice

Flattening WSDL
Still, a number of Web Services stacks do not understand factored-out WSDLs and we are not always dealing with the latest builds and versions, anyway We need a way to put all the WSDL data into one file WCF by default generates multiple files/links Watch out for XML namespaces...

Development Process
Having a look at what a service provides and how it behaves can help understanding how to integrate it into your application architecture simple integration testing services WCF is complex and understanding WCF means seeing WCF debugging services and consumers Not always are the services already implemented and available need ways to mock services

Need to test services whether implemented with WCF or other stacks use WSDL metadata Visual Studio comes with a generic services client test tool WcfTestClient.exe in C:\Program Files (x86)\Microsoft Visual Studio 10.0\ Common7\IDE very basic features, but good enough to take a first stab

WCF & Web Services test client and performance test tool free lite version available (no functional & perf testing)

MockingBird Service Simulator configurable message interceptor backed by a generic simulation engine can act as a stand-in for any web service includes a set of tools to help build and test mock services Plays nicely with the contract-first approach


WCF Debugger Visualizers

Visual Studio 2005 shipped with a feature called debugger visualizers visually view useful information about objects during debugging WCF Visualizers contains Message ChannelDispatcher ServiceDescription ServiceHost ServiceEndpoint (for the client side) ClientRuntime Binding SecurityContext Security OperationContext

Implementation Strategies
Mapping a good architecture seperates the data transfer structures (aka DTOs) from an internal object entity representation need a way to map the data on the outside to the entities on the inside and vice versa manual mapping may be too error-prone and tedious Code generation svcutil and Add Service Reference... are not customizable customizable code generation can be a life safer when using a ChannelFactory-based approach code generation can ease the pain e.g. enhance the DTOs on the consumer side to implement some base functionality

An object-to-object mapper Uses a fluent configuration API to define an object-object mapping strategy Uses a convention-based matching algorithm to match up source to destination values Geared towards model projection scenarios to flatten complex object models to DTOs and other simple objects better suited for serialization, communication, messaging anti-corruption layer between the domain and application layer Combine mapper with a bootstrap task in a ServiceHost pre-init time-consuming setup Alternative: EmitMapper


T4 Templates
T4 is the Text Template Transformation Toolkit built into VS 2010 syntax smells like old ASP code T4 editors available through 3rd party offerings tangible T4 Editor Clarius VisualT4 Look into T4 Toolbox includes several core classes that form a micro-framework for building composite code generators generate multiple output files use existing templates for LINQ to SQL, Entity Framework Use T4 to generate e.g. async contracts from sync interfaces client-side DTOs which inherit from a base class and implement UI-specific interfaces

When COM was the DLL hell, then WCF is maybe the configuration hell A trend can be seen to put configuration into code instead of .config files WCF supports this very well with its verbose API If you need to learn the WCF configuration syntax XSD IntelliSense in Visual Studio SvcConfigEditor tool, especially for diagnostics setup If you need to use WCF configuration files consider the configSource feature


C:\Program Files (x86)\Microsoft Visual Studio 10.0\ Common7\IDE


Feature in the .NET Framework configuration system since .NET 2.0 factor your XML-based configuration into several files works on any configuration WCFs system.serviceModel is a configuration section group need to use configSource attribute on the sub elements
<configuration> <system.serviceModel> <services configSource="services.config" > </services> <bindings configSource="bindings.config"> </bindings> <behaviors configSource=behaviors.config"> </behaviors> </system.serviceModel> </configuration>

On the Wire
In WCF the truth is on the wire. Period. ...and even beyond the wire WCF messages can be traced messages on the transport and the service model layer not the verbatim message WCF can emit verbose tracing data integrated with System.Diagnostics Use SvcTraceViewer to inspect both traces and messages merge your own traces Use Fiddler to see the actual HTTP/S traffic for WCF SOAP and Web/HTTP/REST services


C:\Program Files (x86)\Microsoft Visual Studio 10.0\ Common7\IDE


Acts as a system web proxy You can tweak the requests in Fiddler to test different values or HTTP methods (for WCF Web/HTTP/REST) Fiddler can be extended with custom inspectors e.g. for WCF binary encoder


Optimized data serialization can save bandwidth and also communication/processing time built-in binary encoder does a pretty good job better alternatives through 3rd party encoders/serializers can be useful in mobile scenarios Pub/sub need for communication patterns beyond request-response should be firewall-friendly should be able to span multiple platforms


Protocol Buffers
protobuf binary serialization format used by Google for much of their data communications small in size: efficient data storage (far smaller than xml) cheap to process both at the client and server platform independent: portable between different programming architectures extensible: add new data to old messages protobuf-net for .NET developers can be integrated with WCF by using [ProtoBehavior] by using a Stream type


Fast InfoSet
Joint standard by the ITU-T and ISO/IEC that specifies a binary encoding of the XML Information Set (InfoSet) Most compact encoding when compared to text, binary and MTOM encodings depending on the structure of the message Widely available on Java as well as on other platforms For .NET & WCF we need to purchase WCFXtensions from Noemax pre-built bindings with different channels can use FI encoder in any binding (via FiMessageEncodingBindingElement)


Duplex messaging
WCF offers simple duplex messaging callback contracts binding with duplex support (compositeDuplex binding element in the stack) TCP-based duplex may not even be able to establish a channel through a firewall HTTP-based duplex with wsDualHttp is pretty useless two mutual HTTP connections Long (or smart) polling as viable duplex approach DuplexHttp binding from MSDN not compatible with Silverlights polling duplex, but can be combined


WCF Load Test

Load testing your WCF services based on what you already have Takes a WCF message trace file or Fiddler trace and a WCF client proxy (or a WCF interface contract) Generates a unit test replays the same sequence of calls found in the trace file unit test can then be used to generate load tests and load-test the target service


Dealing with real-world aspects of data in WCF thinktecture DataObjectModel: New HTTP features in WCF.vNext new web/REST pipeline jQuery support WebSockets implementation


Resources Data types interoperability between .NET and Java MockingBird WCF Debugger Visualizer AutoMapper EmitMapper T4 Toolbox

protobuf.-net WCF Xtensions DuplexHttpBinding Fiddler ?ProjectName=silverlightws&DownloadId=12007 WCF Load Test WcfStorm