Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practice for Service and data contracts - WCF

I understand I can apply several options to the ServiceContract (like Name, Namespace) attribute and for OperationContract (Action, ReplyAction)

The same goes to DataContract (Namespace) and DataMember (IsRequired, Name, Order)

How do I determine if I need to apply a particular option or not. What is the best practice/convention I should follow?

like image 524
DotnetDude Avatar asked Mar 02 '10 22:03

DotnetDude


1 Answers

There's no one "best practice" here. Just understand what all of the different arguments are used for.

  • Name should be specified if you want the "public" name of your service to be different from the actual class name (most people don't change this). It's similar for data contracts - use it if you want the name exposed over SOAP/MEX to be different from the property name you use internally.

  • Namespace is something you should change, otherwise it defaults to tempuri.org - you should replace this with a namespace that's relevant to your application.

  • IsRequired should be specified if the type is nullable (i.e. a string) but the field is actually required as part of the contract (for example, a customer must have a name... that is a required field).

  • Order just changes the order that properties appear in the metadata/XML; usually most people don't bother with this unless it's required for compatibility reasons.

like image 178
Aaronaught Avatar answered Sep 28 '22 03:09

Aaronaught