• 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就可以了,问题解决。

  • 相关阅读:
    当一组单选按钮中的一个选中,后文本框为只读属性
    在.net 环境下,进行了伪静态页面处理后,后台的Fckeditor就不能正常显示了
    PL/SQL Developer 8注册码
    选中checkbox后才能填写输入框
    net 试图加载格式不正确的程序。(Exception from HRESULT: 0x8007000B)
    在sql中将varchar型转换成int型再进行排序
    ASP.NET中显示农历时间
    改变自己,拥抱生活
    人生最不值得你去做的事情
    Oracle 中的周、月、日历的查询实现
  • 原文地址:https://www.cnblogs.com/virusswb/p/1658325.html
Copyright © 2020-2023  润新知