Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should WCF services return plain old objects, or the actual class that you're working with?

I am consuming a WCF service from another company, and it is returning an object of type object. Is there a reason not to return the actual class, and return an object that must be cast into the correct form?

For example, if the web service returns an object of type OrderStatus, why would you instead return a plain old object?

Correct me if I'm wrong, but this will require me to get the definition of the OrderStatus class manually (via email or whatever), and put it in my solution. Plus, I will have to explicitly cast the object to an OrderStatus object. Not to mention that the company could change the service to return an object of another type, and my code will stop working.

If the return value of the service was an object of type OrderStatus, the class would be automatically generated for me right?

like image 573
John B Avatar asked Jan 31 '26 10:01

John B


1 Answers

No, definitely not return "object" ! WCF should make use of DataContracts and define full implementations of the request and possibly response objects for each call.

See these two excellent articles on Datacontract basics:

  • WCF tutorial part 2 - Data Contracts
  • WCF Basics - Data Contracts

I have no idea why the developers of those services picked "object" as the return type - doesn't make a whole lot of sense to me!

Marc

like image 71
marc_s Avatar answered Feb 03 '26 00:02

marc_s



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!