Error receiving data from a WCF Service
i have a WCF with several methods: GetAccount, UpdateAccount, DeleteAccont and ListAccount, the first three work well, but ListAccount doesn't. I get an error:
The ListAccount re开发者_如何学JAVAturn a List of Account:
[DataContract]
public class Account
{
private int id;
private String name;
private AccountType accountType;
private Account upperAccount;
private Dictionary<Business, double> porc;
public Account()
{
porc = new Dictionary<Business, double>();
}
[DataMember]
public int Id
{
get { return id; }
set { id = value; }
}
[DataMember]
public String Name
{
get { return name; }
set { name = value; }
}
[DataMember]
public AccountType AccountType
{
get { return accountType; }
set { accountType = value; }
}
[DataMember]
public Account UpperAccount
{
get { return upperAccount; }
set { upperAccount = value; }
}
[DataMember]
public Dictionary<Business, double> Porc
{
get { return porc; }
set { porc = value; }
}
public override string ToString()
{
return name;
}
}
[DataContract]
public enum AccountType : byte
{
[EnumMember]
[Description("Account Type One")]
One = 0,
[EnumMember]
[Description("Account Type Two")]
Two = 1,
}
[DataContract]
public enum Business : byte
{
[EnumMember]
[Description("Business One")]
BusinessOne = 0,
[EnumMember]
[Description("Business Two")]
BusinessTwo = 1,
}
One observation, the list contains 45 items.
Any help will be well received. Thanks
You're likely hitting one of the quotas in WCF - the way to find out for sure is to enable tracing at the server, and look at the traces which will contain an exception telling why the server disconnected the client. Without this information there's just a bunch of guesswork we can do: maybe you're hitting the MaxItemsInObjectGraph quota (can increase using the <dataContractSerializer
> endpoint or service behavior; maybe the graph has a cycle and you need to enable preserveObjectReferences
to deal with it, etc. But only with the traces we'll be able to know for sure.
Is your ListAccount method throwing any errors? Rather than returning a list try using the list's .ToArray method and return an Account[]. I assume your GetAccount method returns a single Account object, which means it is serializable.
精彩评论