如何使用WCF数据协定解决错误-Message ="尝试序列化参数

时间:2015-05-15 08:43:29

标签: wcf datacontractserializer datacontracts

我在两个不同的命名空间中有两个相同内容的数据协定。我已将一个datacontract复制到另一个和

传递给特定方法。但它给出了以下错误并抛出异常。它没有采用那种方法。

请告诉我有关如何解决此问题的任何想法/建议。感谢您的帮助:

异常错误: {" Type' System.Collections.Generic.List`1 [[GlobalWcfServiceLib.TopicDetailsInfo,GlobalWcfContracts,Version = 1.2.2.0,Culture = neutral,  公钥= 17c64733a9775004]]'数据合同名称' ArrayOfTopicDetailsInfo:http://CName.GlobalService/11.1/2010/11'  不是预期的。考虑使用DataContractResolver或将任何静态未知的类型添加到列表中   已知类型 - 例如,通过使用KnownTypeAttribute属性或 将它们添加到传递给DataContractSerializer的已知类型列表中。"}

消息="尝试序列化参数时出错  http://CName.SharedServices.DBServiceLib:subscriptionDataContract。   InnerException消息是' Type' System.Collections.Generic.List`1   [GlobalWcfServiceLib.TopicDetailsInfo,  GlobalWcfContra ...

//////

以下是我的方案:我将数据从dc复制到新数据合同,如下所示。复制后,当我执行createsubscriptions方法时,我得到上述错误。我已经提供了与此问题相关的数据合同和错误的详细信息。请参考。

Method1(SubscriptionDataContracts dc)
{
SubscriptionDataContract subscriptionDataContract = new SubscriptionDataContract();

              List<SubscriptionTopicInfo> topicsInfo = dc.TopicList;
              List<SubscriptionTopic> newTopicsList = new List<SubscriptionTopic>();
              subscriptionDataContract.ExtensionData = dc.ExtensionData;

              subscriptionDataContract.UserID = dc.UserID;

                for (int i = 0; i < topicsInfo.Count; i++)
                {
                    SubscriptionTopic topic = new SubscriptionTopic();
                    topic.DBHandle = topicsInfo[i].DBHandle;
                    topic.Topic = topicsInfo[i].Topic;
                    topic.Target = topicsInfo[i].Target;
                    newTopicsList.Add(topic);    
                }
                subscriptionDataContract.TopicList = newTopicsList;

                CreateSubscriptions(subscriptionDataContract);   //getting the above mentioned error in another dll after going into this method  
  }

//////////////////////////////// //我的数据合同

 [DataContract(Name = "TopicDetailsInfo", Namespace = "http://CName.GlobalService")]
    [Serializable]
    public class TopicDetailsInfo
    {        
        protected object topic;        
        protected object baseObjectType;       
        [DataMember]
        public object BaseObjectType
        {
            get
            {
                return baseObjectType;
            }
            set
            {
                baseObjectType = value;
            }
        }

        [DataMember]
        public object TopicID
        {
            get
            {
                return topic;
            }
            set
            {
                topic = value;
            }
        }

        static public TopicDetailsInfo CreateTopic<T, mT>(IComparable<T> objectType, IComparable<mT> objectID)
        {
            var topicDetails = new TopicDetailsInfo();
            topicDetails.BaseObjectType = objectType;
            topicDetails.TopicID = objectID;
            return topicDetails;

        }

    }


    [DataContract(Name = "SubscriptionTopicInfo", Namespace = "http://CName.GlobalService")]
    [KnownType(typeof(List<TopicDetailsInfo>))]
     [Serializable]
    public class SubscriptionTopicInfo
    {
        private object topic;
        private object target;
        private object creator;
        [DataMember]
        public object Topic
        {
            get
            {
                return topic;
            }
            set
            {
                topic = value;
            }
        }
        [DataMember]
        public object Target
        {
            get
            {
                return target;
            }
            set
            {
                target = value;
            }
        }

        [DataMember]
        public object DBHandle
        {
            get
            {
                return creator;
            }
            set
            {
                creator = value;
            }
        }
        static public SubscriptionTopicInfo CreateSubscriptions<T, mT, nT>(IList<TopicDetailsInfo> topic, IComparable<mT> target, IComparable<nT> handle)
        {

            var subscriptionTopic = new SubscriptionTopicInfo();

            subscriptionTopic.Target = target;
            subscriptionTopic.Topic = topic;
            subscriptionTopic.DBHandle = handle;

            return subscriptionTopic;
        }

    }


    [DataContract(Name = "SubscriptionData", Namespace = "http://CName.GlobalService")]
    [KnownType(typeof(List<SubscriptionTopicInfo>))]
    [Serializable]
    public class SubscriptionDataContracts : IExtensibleDataObject
    {
        private ExtensionDataObject extensionDataObjectValue;       
        [DataMember]         
        public string UserID 
        {
            get;
            set;

        }

        [DataMember]
        public string ProjectID 
        {
            get;
            set;

        }
        [DataMember]
        public string FromDiscipline 
        {
            get;
            set;

        }

        [DataMember]
        public string ModuleID 
        {
            get;
            set;

        }

        [DataMember]
        public string SessionID
        {
            get;
            set;

        }

        [DataMember]
        public List<SubscriptionTopicInfo> TopicList
        {
            get;
            set;
        }        
        public ExtensionDataObject ExtensionData
        {
            get
            {
                return extensionDataObjectValue;
            }
            set
            {
                extensionDataObjectValue = value;
            }
        }

}

0 个答案:

没有答案