在WCF中定义服务合同。 [英] Define Service Contract in WCF.

查看:64
本文介绍了在WCF中定义服务合同。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以将一个类定义为ServiceContract,还是ServiceContrcat应该始终是一个接口?

Can we define a class as a ServiceContract or ServiceContrcat should be always a interface?

推荐答案

请看这里:http://msdn.microsoft.com/en-us/library/ms733070.aspx [ ^ ]



See here:http://msdn.microsoft.com/en-us/library/ms733070.aspx[^]

Quote:

类和接口都代表一组功能,因此,两者都可用于定义WCF服务合同。但是,建议您使用接口,因为它们直接为服务合同建模。如果没有实现,接口只会定义具有特定签名的方法分组。实现服务合同接口并实现了WCF服务。

托管接口的所有好处都适用于服务合同接口:



  • 服务合同接口
  • 单个类可以通过实现这些服务合同接口来实现任意数量的服务合同。
  • 您可以修改服务合同的实现通过更改接口实现,同时服务合同保持不变。
  • 您可以通过实现旧接口和新接口来对服务进行版本控制。旧客户端连接到原始版本,而较新的客户端可以连接到较新版本。
  • Both classes and interfaces represent a grouping of functionality and, therefore, both can be used to define a WCF service contract. However, it is recommended that you use interfaces because they directly model service contracts. Without an implementation, interfaces do no more than define a grouping of methods with certain signatures. Implement a service contract interface and you have implemented a WCF service.
    All the benefits of managed interfaces apply to service contract interfaces:


    • Service contract interfaces can extend any number of other service contract interfaces.
    • A single class can implement any number of service contracts by implementing those service contract interfaces.
    • You can modify the implementation of a service contract by changing the interface implementation, while the service contract remains the same.
    • You can version your service by implementing the old interface and the new one. Old clients connect to the original version, while newer clients can connect to the newer version.

    • 这篇关于在WCF中定义服务合同。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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