Jay
Jay

Reputation: 274

What is the reason keeping attribute within WCF Service?

What is the benefit of keeping attribute in WCF service?

What I mean is why to give them [Datamember] and [Datacontract] and what's advantage and disadvantage?

What happens if I make attributes and its class in different project with simple class library project and I insert its "dll" reference to WCF service class library, which contains all operation that are [ServiceContract] and [operatinconntract] on this attribute.

Upvotes: 1

Views: 48

Answers (2)

tom redfern
tom redfern

Reputation: 31770

Pre-WCF, serialization was done using the XmlSerializer class and by marking a type as [Serializable] it meant that all members were serialized by default.

However with DataContractSerializer which is the preferred serializer used in WCF, members of a class will not be serialized unless indicated.

Re having contract types in a different assembly - yes this is possible, and actually it's best practice to keep your contract types separate from your service implementation assembly.

Upvotes: 0

Andy Nichols
Andy Nichols

Reputation: 3002

WCF parameters need to be serializable. Value types such as int and string will be by default and therefore just work.

DataContractAttribute is used to mark complex types as serializable. See Using Data Contracts for more information.

Upvotes: 1

Related Questions