Best Practices for Service Contracts and Data - WCF

I understand that I can apply several parameters to the ServiceContract attribute (for example, Name , Namespace ) and for OperationContract ( Action , ReplyAction )

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

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

+6
architecture wcf
source share
2 answers

There is no "best practice" here. Just understand what all the different arguments are for.

  • Name should be specified if you want the "public" name of your service to differ from the actual class name (most people do not change this). It is similar to data contracts - use it if you want the name displayed on top of SOAP / MEX to be different from the name of the property that you use internally.

  • Namespace is what you have to change, otherwise it defaults to tempuri.org - you have to replace it with the namespace related to your application.

  • IsRequired should be indicated if the type is null (i.e. string ), but this field is really required as part of the contract (for example, the client must have a name ... which is a required field).

  • Order simply changes the display order of the properties in the metadata / XML; usually most people don’t worry about it unless it is required for compatibility reasons.

+8
source share

No requirements or standards.

Attributes provide parameters, increasing the likelihood that the static specification provided by MS will meet your needs.

So, I would say that it is best practice to understand the options and how to apply them to your requirements.

0
source share

All Articles