
Chapter 11: Deploying Web Services with WCF | 305 |
The GetDataUsingDataContract method illustrates a method that uses a custom type, CompositeType, as a parameter and return type. Being a custom type, CompositeType has attributes that help define its contract: DataContract and DataMember. The DataContract attribute identifies CompositeType as a type that can be included in a WCF service contact. Without the DataContract attribute, a type can’t be included as part of the service contract. The DataMember attribute decorates type members that are part of the contract for this service. Without the DataMember attribute, a type member will not be visible as part of the contract.
Creating Your Own Contract
We won’t explicitly construct our data types for DataContracts, as shown in the CompositeType in Listing
Now, instead of creating a custom type and copying LINQ to SQL entity data into the custom type and returning the custom type, it will be possible to perform a LINQ to SQL query and return the LINQ to SQL entity.