Download presentation
Presentation is loading. Please wait.
Published byCharles Jackson Modified over 9 years ago
2
2 Productive Windows Communication Foundation Jeremy Boyd Mindscape MSDN Regional Director – New Zealand jeremy@mindscape.co.nz SOA315
3
3 Legends Juval Lowy – Regional Director Silicon Valley Christian Weyer – Regional Director Germany
4
4 Agenda Some useful tools Unit Testing Services using In Process Hosting Per operation scoped extensions Tips around Data Contracts Managing Faults Windows Forms and WCF Hosting services under IIS 7
5
5 Useful Tools A number of useful tools were provided with.NET 3.0 SvcTraceViewer SvcConfigEditor New tools with.NET 3.5 Service Test Host Service Test Client
6
6 Sample Test Host Useful Tools.NET 3.5 ships with simple generic host WcfSvcHost.exe Must provide as command line arguments Service class assembly Class library or application assembly Config file (may be separate from normal) Can optionally start a test client at the same time
7
7 Sample Test Client Useful Tools.NET 3.5 ships with simple generic test client WcfTestClient.exe Must provide service metadata as command line arguments E.g. WcfTestClient http://server:port/urlhttp://server:port/url
8
8 Useful Tools
9
9 Extra Tips Useful Tools Can host within Visual Studio for F5’ing by using “Start External Program” Can also have it call to the WcfTestClient! Can use with WCF 3.0 and Visual Studio 2005 if required – just add WcfSvcHost to the GAC
10
10 Unit Testing with Services Testing Service Classes is no problem Create class and invoke methods.. Testing classes with dependencies on services is a problem Should ideally remove dependencies What if execution context matters?
11
11 Hosting In-Process Need a simple way to host a service in-process so we can simulate the WCF pipeline Want to support security, transaction flow etc Ideally avoid any “implementation” code Proxy implementation Config files ServiceHost wrapper
12
12 Hosting In-Process
13
13 Per Operation Scope Extensions Use an IDispatchMessageInspector to deal with “per call” concerns Use an IServiceBehavior to apply the message inspector I personally favour an attribute based approach Add and reference your extensions from OperationContext.Current.Extensions
14
14 Tips for Data Contracts General issues with.. Working with OO mismatches Working with DataTables / DataSets DTO construction Some useful advancements in 3.5 SP1 Automatic support for graph serialization POCO support for serialization
15
15 Operations Overloading Tips for Data Contracts Cannot overload operations with services Can manually enable overloading Use Name property to alias overloaded operations on service Generate proxy on client side Rename proxy methods to generate overloading Use Name property to alias overloaded methods on proxy Make calls on internal channel using the overloaded methods
16
16 Datasets and Tables Tips for Data Contracts ADO.NET makes using DataSet and DataTable easy (too easy?) Consider implications of passing dataset and data table Inside layers of app probably fine Consider implications of publishing schema Across technology boundaries consider returning arrays or other neutral representation
17
17 Tips for Data Contracts
18
18 Fault Debugging Two main desires for debugging Providing detail of errors or exceptions Flowing exceptions back to clients Remember to use tracing information Existing SDK tools help with this SvcConfigEditor SvcTraceViewer
19
19 Providing Exception Details Fault Debugging By default, WCF will mask service exceptions Service exceptions returned as FaultException This is best practice (don’t leak) However, sometimes this is needed or useful.. IncludeExceptionDetailInFaults property of ServiceBehavior attribute Defaults to false Should only use in “debug” mode
20
20 Flowing Exceptions to the Client Fault Debugging When debugging it is useful to flow exceptions FaultException class in the ServiceModel framework already caters for this Initialized with original exception Detail.Type contains name of service exception Message contains original exception message
21
21 Managing Faults
22
22 Windows Forms and WCF Form itself can be a service Simplifies reaching into the form Self-hosted Subscriber to update events Form needs to be a singleton Use InstanceContextMode.Single Can get a bit messy to manage UI updates however..
23
23 Windows Forms and WCF
24
24 Hosting with IIS 7 Self Hosted Process Self Hosted Process W3SVC.NET Worker Service Host HTTP NET.TCP NET.PIPE NET.MSMQ WAS
25
25 Hosting with IIS 7 / WAS
26
26 Configuration Expose metadata at least on your test instances Supports test clients and easier development Look to understand and tweak bindings to suit requirements, e.g. Security, Transaction modes and Throttling
27
27 Throttling Number of out of the box defaults for throttling Sessions: 10 Calls: 16 Instances: 10 “Limits? We dont need no stinkin limits!”
28
28 Managing the Throttle
29
29 Summary Useful Tools Sample Test Host and Client Hosting In-Process InProcFactory pattern simplifies life Per Operation Extensions Data Contract tips Overloading using Name on OperationContract Easier DTOs using.NET 3.5 extensions
30
30 Summary Fault Debugging Leverage ExceptionDetail and flowing for debugging Remember to switch off for release! Hosting inside Windows Forms FormHost pattern works quite well Hosting under IIS 7 / WAS IIS 7 can host HTTP(s), TCP, Named Pipes, MSMQ Remember to enable the protocol Remember to define the appropriate endpoints
31
31 Resources Programming WCF Services Juval Lowy, O'Reilly 2007 http://www.idesign.net Code library Coding standards My details: jeremy@mindscape.co.nz http://turtle.net.nz/blog
32
32
33
33 Resources www.microsoft.com/teched Tech·TalksTech·Ed Bloggers Live SimulcastsVirtual Labs http://microsoft.com/technet Evaluation licenses, pre-released products, and MORE! http://microsoft.com/msdn Developer’s Kit, Licenses, and MORE!
34
34 © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.