zoukankan      html  css  js  c++  java
  • Silverlight3+WCF遇到的问题(二):wcf system.servicemodel.communicationexception Virus

      以前我访问的数据库都是一张表,没有关联,昨天添加了两张表,一共两张表,用户表和用户类型表,然后修改了原来的两个实体类

      用户信息实体类

    代码
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Runtime.Serialization;

    namespace Domain.Entity
    {
        [DataContract]
        
    public class Customer : INotifyPropertyChanged
        {
            
    private int _intCustomerId;
            
    private string _strCustomerName;
            
    private string _strCustomerCode;
            
    private CustomerType  _CustomerType;
            
    private int _intCustomerTypeId;

            [DataMember ]
            
    public virtual  int CustomerTypeId
            {
                
    get { return _intCustomerTypeId; }
                
    set
                {
                    _intCustomerTypeId 
    = value;
                    OnPropertyChanged(
    "CustomerTypeId");
                }
            }

            [DataMember ]
            
    public virtual  CustomerType  CustomerType
            {
                
    get { return this._CustomerType; }
                
    set
                {

                    
    this._CustomerType = value;
                    OnPropertyChanged(
    "CustomerType");
                }
            }

            [DataMember]
            
    public virtual int CustomerId
            {
                
    get { return this._intCustomerId; }
                
    set
                {
                    
    this._intCustomerId = value;
                   OnPropertyChanged(
    "CustomerId");
                }
            }
            [DataMember]
            
    public virtual string CustomerName
            {
                
    get { return this._strCustomerName; }
                
    set
                {
                    
    this._strCustomerName = value;
                   OnPropertyChanged(
    "CustomerName");
                }
            }
            [DataMember]
            
    public virtual string CustomerCode
            {
                
    get { return _strCustomerCode; }
                
    set
                {
                    
    this._strCustomerCode = value;
                    OnPropertyChanged(
    "CustomerCode");
                }
            }

            
    #region INotifyPropertyChanged Members

            
    public event PropertyChangedEventHandler PropertyChanged;

            
    #endregion
            
    private void OnPropertyChanged(string propertyName)
            {
                
    if (PropertyChanged != null)
                {
                    PropertyChanged(
    thisnew PropertyChangedEventArgs(propertyName));
                }
            }
        }
    }

      用户类型实体类

      

    代码
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Runtime.Serialization;

    namespace Domain.Entity
    {
        [DataContract]
        
    public class CustomerType : INotifyPropertyChanged
        {
            
    private string _strCustomerTypeName;
            
    private int _intCustomerTypeId;
            
    private IList  <Customer> _customers;
            [DataMember ]
            
    public virtual  int CustomerTypeId
            {
                
    get { return this._intCustomerTypeId; }
                
    set
                {

                    
    this._intCustomerTypeId = value;
                    OnPropertyChanged(
    "CustomerTypeId");
                }
            }

            [DataMember]
            
    public virtual string CustomerTypeName
            {
                
    get { return this._strCustomerTypeName; }
                
    set
                {
                    
    this._strCustomerTypeName = value; OnPropertyChanged("CustomerTypeName");
                }
            }
            [DataMember]
            
    public virtual IList<Customer> Customers
            {
                
    get { return this._customers; }
                
    set
                {
                    
    this._customers = value;
                    OnPropertyChanged(
    "Customers");
                }
            }
            
    #region INotifyPropertyChanged Members

            
    public event PropertyChangedEventHandler PropertyChanged;

            
    #endregion
            
    private void OnPropertyChanged(string propertyName)
            {
                
    if (PropertyChanged != null)
                {
                    PropertyChanged(
    thisnew PropertyChangedEventArgs(propertyName));
                }
            }
            
    public override string ToString()
            {
                
    return CustomerTypeName;
            }
        }
    }
      

      请注意上面的这个红色部分IList,本来我是想返回集合的,一想针对接口编程,然后就写了一个IList,可是问题就出来了,原来好好的东西,就跑不了了,一个劲的报错。

      在SL3客户端的代码

      

    void client_GetCustomerCompleted(object sender, GetCustomerCompletedEventArgs e)
            {
                LayoutRoot.DataContext 
    = e.Result;
            }

      报错,就在e.Result,报错wcf system.servicemodel.communicationexception  我就开始找啊找,google啊google,很多人提出这个错误,就是没有回答。后来我在这篇请教当返回自定义类型时如何通过<declaredTypes>实现序列化帖子中找到了一些提示信息,他说“查了一些帮助,发现是由于返回类型中有个IList,所以无法序列化”,恍然大悟,还是WCF版的版主Frank Xu Lei厉害啊,哈哈。

      修改成List就可以了,问题解决。

  • 相关阅读:
    如何利用python制作微信好友头像照片墙?
    机器学习入门路线和资源
    突然“被辞职”的时候,原来可以拿到这么多钱!
    一个致命的 Redis 命令,导致公司损失 400 万
    程序员:想知道你每天按了多少次键盘吗?
    想了解真实的中国历史吗?建议看看这10部历史纪录片,受益终生!
    SpringBlade 2.0-RC3 发布,全新的微服务开发平台
    Syncd-开源自动化部署工具
    学习Spring Boot看这两个开源项目就够了!非得值得收藏的资源
    大型视频直播平台架构由浅入深详细讲解
  • 原文地址:https://www.cnblogs.com/virusswb/p/1658325.html
Copyright © 2011-2022 走看看