Top Banner
WCF BEST PRACTICE Yu Guan | Microsoft MVP
14

Wcf best practice

Apr 12, 2017

Download

Software

Yu Guan
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Wcf best practice

WCF BEST PRACTICE

Yu Guan | Microsoft MVP

Page 2: Wcf best practice

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

Page 3: Wcf best practice

WCF ARCHITECTURE GUIDELINE Contract Segmentation Parameters and Return Values Data Mapping Service Invocation Service Granularity Transferring Large Data Sets Load Balancing

Page 4: Wcf best practice

Contract Segmentation You should separate logically related interfaces, contracts,

entities, messages, and enumerations into individual projects. You should implement WCF Services as DLLs.

Page 5: Wcf best practice

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.

Page 6: Wcf best practice

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.

Page 7: Wcf best practice

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.

Page 8: Wcf best practice

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

Page 9: Wcf best practice

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

Page 10: Wcf best practice

Load BalancingNo Security Transport Security

Message Security

Page 11: Wcf best practice

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

Page 12: Wcf best practice

DEMO

Page 13: Wcf best practice

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.

Page 14: Wcf best practice

THANK YOU!