IExtensibleDataObject使用在客户端 [英] IExtensibleDataObject usage in clients

查看:117
本文介绍了IExtensibleDataObject使用在客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经转换我的web服务,其中有一些datacontracts WCF服务。作为最佳实践它被提及,并建议这些DataContracts应该IExtensibleDataObject继承。我得到的是,除了或删除数据成员的情况下,IExtensibleDataObject是有帮助的地步。但我没能获得如何将客户端访问已删除数据成员。这里是我的代码:



<预类=郎-CS prettyprint-覆盖> [的ServiceContract(命名空间=htt​​p://mycompany.com/ 2010/08 /)]
公共类为MyWebService {
[OperationContract的]
公务员添加(员工EMP)
{
//一些处理
}
}

[DataContract(NAME =雇员,命名空间=htt​​p://mycompany.com/2010/08/)]
公共类员工:IExtensibleDataObject {
[数据成员]公共字符串名字;
[数据成员]公共字符串姓氏;

公共ExtensionDataObject ExtensionData {搞定;组; }
}

现在在我的Web服务的下一个版本我做了一些改动DataContract为

  [DataContract(NAME =雇员,命名空间=htt​​p://mycompany.com/2010/09/) ] 
公共类员工:IExtensibleDataObject {
[数据成员]公共字符串名字;
[数据成员]公共字符串姓氏;
[数据成员(IsRequired =真)]公共字符串中间名;

公共ExtensionDataObject ExtensionData {搞定;组; }
}



不过我的客户正在访问我的web服务的旧版本现在正错误不提供的中间名域。我仍然困惑的IExtensionDataObject的使用。


解决方案

恐怕这不是IExtensibleDataObject的正确用法,在IExtensibleDataObject接口旨在支持版本往返,对前向兼容性这个MSDN文章的读:



http://msdn.microsoft.com/en-us/library/ms731083.aspx



和这里是对一般的数据合同版本的最佳实践的另一篇文章:
http://msdn.microsoft .COM / EN-US /库/ ms733832.aspx


I have converted my web service to wcf service which has some datacontracts. As a best practice it is mentioned and advisable that the DataContracts should inherit from IExtensibleDataObject. I get the point that in case of addition or removal of datamembers, IExtensibleDataObject is helpful. But i am not able to get how will the clients access removed datamembers. Here is my code:

[ServiceContract(Namespace = "http://mycompany.com/2010/08/")]
public class MyWebService {
    [OperationContract]
    public Employee Add(Employee emp)
    {
        // Some Processing
    }
}

[DataContract(Name = "Employee", Namespace = "http://mycompany.com/2010/08/")]
public class Employee : IExtensibleDataObject {
    [DataMember] public string FirstName;
    [DataMember] public string LastName;

    public ExtensionDataObject ExtensionData  { get; set; }
}

Now in my next version of web service I made some changes to DataContract as

[DataContract(Name = "Employee", Namespace = "http://mycompany.com/2010/09/")]
public class Employee : IExtensibleDataObject {
    [DataMember] public string FirstName;
    [DataMember] public string LastName;
    [DataMember(IsRequired = true)] public string MiddleName;

    public ExtensionDataObject ExtensionData  { get; set; }
}

However my client that is accessing my older version of web service is now getting error for not supplying the MiddleName field. I am still confused for the usage of IExtensionDataObject.

解决方案

I'm afraid that's not the correct usage of IExtensibleDataObject, the IExtensibleDataObject interface is designed to support version round-tripping, have a read of this MSDN article on forward compatibility:

http://msdn.microsoft.com/en-us/library/ms731083.aspx

And here's another article on best practices on Data Contract versioning in general: http://msdn.microsoft.com/en-us/library/ms733832.aspx

这篇关于IExtensibleDataObject使用在客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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