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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With