mcass20
mcass20

Reputation: 1688

Why should I use data contracts instead of parameters for WCF service calls?

Why should I use data contracts instead of parameters for WCF service method calls?

Upvotes: 1

Views: 1773

Answers (2)

marc_s
marc_s

Reputation: 755371

You're not using DataContracts instead of parameters.... if your parameters are atomic types, like string and int, you don't need data contracts on these.

But if you create a compound type, which is often beneficial is you have five or more parameters, then you need to decorate that class type with [DataContract] to make it clear to WCF that that's the class you want to use and serialize.

Having two, three simple parameters is great - but as soon as you have more than that, or if you need to pass back more than a single value, you typically should use a class to group/hold those values together.

Upvotes: 3

Darin Dimitrov
Darin Dimitrov

Reputation: 1039438

A DataContract is just an attribute which is used to decorate the classes you will be using as parameters to your service methods. Starting from .NET 3.5 SP1 you no longer need to decorate your objects with DataContract/DataMember attributes, all public properties will be automatically serialized.

Upvotes: 2

Related Questions