开发者

Error receiving data from a WCF Service

开发者 https://www.devze.com 2023-04-07 11:08 出处:网络
i have a WCF with several methods: GetAccount, UpdateAccount, DeleteAccont and ListAccount, the first three work well, but ListAccount doesn\'t.

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:

Error receiving data from a WCF Service

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号