Silverlight 我的数据合同有什么问题?

Silverlight 我的数据合同有什么问题?,silverlight,wcf-ria-services,Silverlight,Wcf Ria Services,好的,这是我的RIA服务数据合同: public class ZipLocationDC { [Key] public String ZipCode { get; set; } [Editable(false)] public double Latitude { get; set; } [Editable(false)] public double Longitude { get; set; } } 我还有数百个与此非常类似的实体(即,只具有

好的,这是我的RIA服务数据合同:

public class ZipLocationDC
{
    [Key]
    public String ZipCode { get; set; }

    [Editable(false)]
    public double Latitude { get; set; }

    [Editable(false)]
    public double Longitude { get; set; }
}
我还有数百个与此非常类似的实体(即,只具有基本类型属性的简单类)。由于某种原因,我得到了以下例外:

名为“GetZipLocation”的操作不符合要求的 签名。返回类型必须是实体或复杂类型 实体或复杂类型的集合,或预定义 可序列化类型

我做错了什么?我不知道您为什么需要它,但这是我的服务操作:

    [Invoke]
    public ZipLocationDC GetZipLocation(String a_strZipCode)
    {
        var zipCodes = from zipCode in ObjectContext.ZipCodes
                       where zipCode.Code == a_strZipCode
                       select zipCode;

        if (!zipCodes.Any())
            return null;

        var dLatitude = zipCodes.Average(i => i.Latitude);
        var dLongitude = zipCodes.Average(i => i.Longitude);

        return new ZipLocationDC
            {
                ZipCode = a_strZipCode,
                Latitude = dLatitude,
                Longitude = dLongitude
            };
    }

我对RIA服务感到非常厌倦。我也使用直接的WCF,但使用RIA时,我总是遇到类似这样的奇怪问题。它几乎不值得使用。

这太愚蠢了,为什么我要尽快切换到WCF。作为查询操作的结果,我必须包含我的数据契约(
ZipLocationDC
)。我只返回null。我将此代码添加到我的服务定义中

    /// <summary>
    /// This method does nothing but expose ZipLocationDC as an read-only entity.
    /// </summary>
    /// <returns>Null.</returns>
    [Query]
    public IQueryable<ZipLocationDC> GetZipLocations()
    {
        return null;
    }
//
///此方法只将ZipLocationDC公开为只读实体。
/// 
///空。
[查询]
公共可查询的GetZipLocations()
{
返回null;
}

RIA服务是如此痛苦地限制。我知道它对你有帮助,但它更像是一个问题,而不是一个助手

嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎!!我今天刚碰到这个。我讨厌服务。谢谢你的回复。我推荐WCF。它不会握着你的手,但你也不会得到任何这些愚蠢的惊喜。我从2005年就开始做WCF了。“完全正确!”(对你来说)。我现在对所有微软汽车魔法巫术持怀疑态度。这一次是Ria ServicesWell,没有,有些可以正常工作。例如,确保这些东西工作得非常好。这要看情况了。伏都教也快把我逼疯了。