Last post Oct 08, 2012 05:44 PM by ozkary
Oct 07, 2012 03:18 PM|dotnetterAMG123|LINK
Hello - Do you ever return primitive types from a WCF service as opposed to a DataContract? I was wondering if and when it's ever appropriate to do this and what the general practices/recommendations are for this?
Oct 08, 2012 05:44 PM|ozkary|LINK
The desicion to return premitive types depends on your requirements. You may have a service that just returns an amount or distance. All these values can be returned using primitive types. For example, a distance calculator service may just return an int
value to indicate the distance in miles. The webmethod could also return a negative number to indicate that the calculation was invalid instead of raising an exception in a fault contract.
The recomendations for this is to define what your service should provide and return the corresponding information. Why return a complex type when you only need to return a number? You also need to create an standard on the way you provide feedback on errors
for the consumer applications. i.e. return negative values or raise an exception in a fault contract.
hope it helps.