WCF BEST PRACTICE Yu Guan | Microsoft MVP
WCF BEST PRACTICE
Yu Guan | Microsoft MVP
Meet Yu Guan | @askguanyu
twitter.com/askguanyulinkedin.com/in/yuguanaskguanyu.wordpress.comdevlib.codeplex.com
Microsoft MVPSpeaker, Blogger, Hacker, Coder, Maker, GamerAzure, IoT, Cross-platform Apps, GIS, Services
WCF ARCHITECTURE GUIDELINE Contract Segmentation Parameters and Return Values Data Mapping Service Invocation Service Granularity Transferring Large Data Sets Load Balancing
Contract Segmentation You should separate logically related interfaces, contracts,
entities, messages, and enumerations into individual projects. You should implement WCF Services as DLLs.
Parameters and Return Values You should mark your types with the DataContractAttribute and
DataMemberAttribute attributes to create a data contract, which is the portion of the service contract that describes the data that your service operations exchange.
You should not use Out and Ref Parameters. You should not use System.IO.Stream and derived types as
parameter or return value. You should not use System.IO.Stream and derived types inside
of data contracts.
Data Mapping You should centralize your types into a common project in
order to share the same data elements. You should check Reuse types in referenced assemblies check
box.
Service Invocation You should centralize your contracts into a separate project.
The calling service can then reference these contract projects, which allows you to invoke the services without a proxy.
Service Granularity You should weigh the tradeoffs and benefits of many chatty
calls versus a few chunky calls.
Client Service 1
chatty calls
Service 2
chunky calls
Transferring Large Data Sets You should consider using compressing when sending or
receiving large data. You can consider using streaming mode, but keep in mind that
streaming mode has lots of restrictions
Load BalancingNo Security Transport Security
Message Security
DevLib.ServiceModel NuGet: https://www.nuget.org/packages/DevLib.ServiceModel/ Source code:
https://devlib.codeplex.com/SourceControl/latest#Main/Source/DevLib.ServiceModel/
Address Binding ContractWCF Config File
WCF Config File
WCF Config File
Address String Binding Type WCF DLLsBinding Instance Contract Type
No SecurityService Host Client Invocation
Address Binding ContractWCF Config File WCF Config File InterfaceAddress String Binding Type
Binding Instance
DEMO
APPENDIX
Wording Intent
Do... This standard or practice should be followed in all cases. If you think that your specific application is exempt, it probably isn't.
Do Not... This standard or practice should never be applied.
You should... This standard or practice should be followed in most cases.
You should not... This standard or practice should not be followed, unless there's reasonable justification.
You can… This standard or practice can be followed if you want to; it's not necessarily good or bad. There are probably implications to following the practice (dependencies, or constraints) that should be considered before adopting it.
THANK YOU!