views:

1358

answers:

1

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?

+3  A: 

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:

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

marc_s
Right, this question was my sanity check! It doesn't make any sense to me either.
SkippyFire
This will happen if the XSD is over-general. For instance, if `<xs:any>` is returned, .NET will see it as `object`.
John Saunders
Ah, good point, John!
marc_s
Thanks @marc_s the WCF Basics - Data Contracts link has great info. The first link isn't working though, it may have been taken down?
campo