wcf tools and libraries print

28
Christian Weyer | thinktecture [email protected] Jenseits von System.ServiceModel WCF Tools und Libraries

Upload: martin-schmeller

Post on 24-Oct-2014

73 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: WCF Tools and Libraries Print

Christian Weyer | thinktecture [email protected]

Jenseits von System.ServiceModel

WCF Tools und Libraries

Page 2: WCF Tools and Libraries Print

2

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

• http://blogs.thinktecture.com/cweyer

[email protected]

Page 3: WCF Tools and Libraries Print

3

Agenda

• Modeling contracts

• Development process

• Implementation strategies

• Configuration

• On the Wire

• Communication

• Under Load

• Misc

Page 4: WCF Tools and Libraries Print

4

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 denomi-

nator

Page 5: WCF Tools and Libraries Print

5

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

Page 6: WCF Tools and Libraries Print

6

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...

Page 7: WCF Tools and Libraries Print

7

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

Page 8: WCF Tools and Libraries Print

8

WcfTestClient

• 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

Page 9: WCF Tools and Libraries Print

9

wcfstorm

• WCF & Web Services test client and performance test tool

– free lite version available (no functional & perf testing)

Page 10: WCF Tools and Libraries Print

10

MockingBird

• 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

Page 11: WCF Tools and Libraries Print

11

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

Page 12: WCF Tools and Libraries Print

12

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

Page 13: WCF Tools and Libraries Print

13

AutoMapper

• 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

Page 14: WCF Tools and Libraries Print

14

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

Page 15: WCF Tools and Libraries Print

15

Configuration

• 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

Page 16: WCF Tools and Libraries Print

16

SvcConfigEditor

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

Common7\IDE

Page 17: WCF Tools and Libraries Print

17

configSource

• Feature in the .NET Framework configuration system since

.NET 2.0

– factor your XML-based configuration into several files

– works on any configuration

• WCF‘s 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>

Page 18: WCF Tools and Libraries Print

18

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

Page 19: WCF Tools and Libraries Print

19

SvcTraceViewer

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

Common7\IDE

Page 20: WCF Tools and Libraries Print

20

Fiddler

• 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

Page 21: WCF Tools and Libraries Print

21

Communication

• 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

Page 22: WCF Tools and Libraries Print

22

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

Page 23: WCF Tools and Libraries Print

23

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)

Page 24: WCF Tools and Libraries Print

24

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 Silverlight‘s polling duplex, but can be

combined

Page 25: WCF Tools and Libraries Print

25

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

Page 26: WCF Tools and Libraries Print

26

Misc

• Dealing with real-world aspects of data in WCF

– thinktecture DataObjectModel:

http://dataobjectmodel.codeplex.com/

• New HTTP features in WCF.vNext

– new web/REST pipeline

– jQuery support

– WebSockets implementation

– http://wcf.codeplex.com/

Page 27: WCF Tools and Libraries Print

27

Resources

• http://blogs.thinktecture.com/cweyer

[email protected]

• Data types interoperability between .NET and Java

– http://msdn.microsoft.com/en-us/netframework/gg413252.aspx

• WSCF.blue

– http://wscfblue.codeplex.com/

• MockingBird

– http://mockingbird.codeplex.com/

• WCF Debugger Visualizer

– http://wcfvisualizer.codeplex.com/

• AutoMapper

– http://automapper.codeplex.com/

• EmitMapper

– http://emitmapper.codeplex.com

• T4 Toolbox

– http://t4toolbox.codeplex.com/

Page 28: WCF Tools and Libraries Print

28

Resources

• protobuf.-net

– http://code.google.com/p/protobuf-net/

• WCF Xtensions

– http://www.noemax.com/products/wcfx/index.html

– http://www.noemax.com/products/fastinfoset/features.html

• DuplexHttpBinding

– http://archive.msdn.microsoft.com/duplexhttp

• Fiddler

– http://www.fiddler2.com/fiddler2/

– http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx

?ProjectName=silverlightws&DownloadId=12007

– http://identitymodel.codeplex.com/releases/view/52187

• WCF Load Test

– http://wcfloadtest.codeplex.com/

• WcfStorm

– http://www.wcfstorm.com/wcf/home.aspx