如果WCF服务返回纯老物件,或者你正在使用的实际类? [英] Should WCF services return plain old objects, or the actual class that you're working with?

查看:64
本文介绍了如果WCF服务返回纯老物件,或者你正在使用的实际类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我消费从另一家公司的WCF服务,它返回类型对象的对象。有没有理由不返回实际的类,并返回必须转换成正确的形式对象?



例如,如果Web服务返回的对象键入 OrderStatus ,为什么你会,而不是返回一个普通的老式对象



纠正我,如果我错了,但是这将需要我手动获得 OrderStatus 类的定义(通过电子邮件或其他),并把它放在我的解决方案。另外,我必须将目标明确地强制转换为 OrderStatus 对象。更何况,该公司可能会改变服务来回报另一种类型的对象,我的代码将停止工作。



如果该服务的返回值是一个对象类型 OrderStatus ,类将自动为我的权利?


解决方案
<产生p>不会,绝对不会返回对象! 。WCF应利用DataContracts并定义为每个呼叫请求和可能的响应对象的全面实施



查看Datacontract基础这两个优秀的文章:





我不知道为什么这些服务的开发商挑对象的返回类型 - !不作一大堆的道理给我。



马克


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?

解决方案

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

这篇关于如果WCF服务返回纯老物件,或者你正在使用的实际类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆