Silverlight3+WCF遇到的问题(二):wcf system.servicemodel.communicationexception

 

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

 

  用户信息实体类

 

ExpandedBlockStart.gif 代码
<!--<br/ /><br/ />Code highlighting produced by Actipro CodeHighlighter (freeware)<br/ />http://www.CodeHighlighter.com/<br/ /><br/ />--> 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(
this new  PropertyChangedEventArgs(propertyName));
            }
        }
    }
}

 

  用户类型实体类

  

ExpandedBlockStart.gif 代码
<!--<br/ /><br/ />Code highlighting produced by Actipro CodeHighlighter (freeware)<br/ />http://www.CodeHighlighter.com/<br/ /><br/ />--> 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(
this new  PropertyChangedEventArgs(propertyName));
            }
        }
        
public   override   string  ToString()
        {
            
return  CustomerTypeName;
        }
    }
}
  

 

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

  在SL3客户端的代码

  

<!--<br/ /><br/ />Code highlighting produced by Actipro CodeHighlighter (freeware)<br/ />http://www.CodeHighlighter.com/<br/ /><br/ />--> 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就可以了,问题解决。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值