我可以添加一个数据成员在WCF一个CollectionDataContract? [英] Can I add a DataMember to a CollectionDataContract in WCF?

查看:362
本文介绍了我可以添加一个数据成员在WCF一个CollectionDataContract?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我已经装饰了CollectionDataContract一个集合类。集合类也有,我想传递给服务客户端类的属性。我曾尝试添加[数据成员],以该财产,但它并没有将它添加到类,当我更新了客户端。

I have a collection class that I have decorated with a CollectionDataContract. The collection class also has a property on the class that I would like to be passed to the service client. I have tried adding [DataMember] to that property but it didn't add it to the class in the client when I updated.

任何WCF专家在那里有什么帮助提供?

Any WCF experts out there have any help to offer?

推荐答案

一个有效的解决方案张贴在我的博客:

A working solution is posted on my blog:

<一个href="http://borismod.blogspot.com/2009/04/wcf-collectiondatacontract-and.html">http://borismod.blogspot.com/2009/04/wcf-collectiondatacontract-and.html

UPD:谢谢,您的评论,杰夫。 这里是这里的非通用类的摘要。一个完整的通用的解决方案可以在我的博客一篇新的文章中找到: <一href="http://borismod.blogspot.com/2009/06/v2-wcf-collectiondatacontract-and.html">http://borismod.blogspot.com/2009/06/v2-wcf-collectiondatacontract-and.html

UPD: Thanks, for your comment, Jeff. Here is a summary here of a non generic class. A full generic solution can be found in a new post in my blog: http://borismod.blogspot.com/2009/06/v2-wcf-collectiondatacontract-and.html


[DataContract(IsReference = true)]    
public class EntityCollectionWorkaround : ICollection 
    {

        #region Constructor
        public EntityCollectionWorkaround()
        {
            Entities = new List();
        } 
        #endregion

        [DataMember]
        public int AdditionalProperty { get; set; }

        [DataMember]
        public List Entities { get; set; }

        #region ICollection Members
          // Implement here members of ICollection by wrapping Entities methods
        #endregion

        #region IEnumerable Members
          // Implement here members of IIEnumerable by wrapping Entities methods
        #endregion

    }

这篇关于我可以添加一个数据成员在WCF一个CollectionDataContract?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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