【发布时间】:2011-06-16 13:50:21
【问题描述】:
当我尝试创建新的 WCF 项目时,Visual Studio 2010 默认会生成以下内容。有一个用于定义方法的接口(WCF 术语中的操作合同)和一个排他类,用于定义服务合同的定义将使用的数据。
namespace iAMProxyService
{
// NOTE: If you change the interface name "IService1" here, you must also update the reference to "IService1" in Web.config.
[ServiceContract]
public interface IProxyService
{
[OperationContract]
string GetData(int value);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
// TODO: Add your service operations here
}
// Use a data contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";
[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
}
现在我想知道 DataContract 是否可以帮助减少客户端和服务器之间的任何依赖关系。也就是说,我觉得当我更改数据合同时,我不必重新编译客户端代码,因为它只是具有接口(服务合同)。我的假设是正确的还是我错过了什么!?
【问题讨论】:
-
我的理解是,如果你单独关心接口,如果客户端使用的接口没有改变,那么你不需要重新编译或重新分发。