默认情况下,Visual Studio 2010在尝试创建新的WCF项目时会生成以下内容。有一个接口用于定义方法(WCF术语中的操作契约)和一个定义服务契约定义将使用的数据的排他类。需要在WCF中分离DataContracts和ServiceContract
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是否可以帮助减少客户端和服务器之间的任何类型的依赖。也就是说,我觉得当我更改数据合同时,我不必重新编译客户端代码,因为它只是具有接口(服务契约)。我的假设是正确的还是我错过了什么!?
这是我的理解,如果你分开与接口的关注,如果客户端中使用的接口不改变,那么你不需要重新编译或重新分配。 – Nair 2011-06-16 13:54:42