RIA服务 - 没有数据库?

时间:2010-03-15 15:12:07

标签: .net silverlight web-services service ria

西洛!

我需要编写一个RIA服务来从Silverlight 3.0应用程序调用Java webservices。 我正在测试东西是如何工作的,在我的Web应用程序中我有一个MyData类,它有2个属性(int ID,string Text):

namespace SilverlightApplication1.Web
{
    public class MyData
    {
        [Key]
        public int ID { get; set; }

        public string Text { get; set; }
    }
}

然后我编写了简单的DomainService:

[EnableClientAccess()]
public class MyService : DomainService
    {
        public IQueryable<MyData> GetMyData(string Url)
        {
                    // here I will call my WebService

            List<MyData> result = new List<MyData>();
            result.Add(new MyData { ID = 1, Text = Url });
            return result.AsQueryable();
        }
    }
}

如何将数据存入我的SL应用程序?现在我有了这个:

命名空间SilverlightApplication1 {     public partial class MainPage:UserControl     {         公共MainPage()         {             的InitializeComponent();             MyContext context = new MyContext();         }     } }

我打电话并加载但是没有暗示(异常或空值)......

我有Invoke注释,但MyData不是TEntity,我也不能使用Strings或其他简单类型......:/ 我正在阅读和阅读帖子,没有什么能像它应该的那样......

任何帮助都会非常感激。

谢谢!

1 个答案:

答案 0 :(得分:0)

您的代码在服务器上看起来不错。您将希望将上下文移动到MainPage构造函数之外,并向您的加载操作添加回调。还要确保将System.ServiceModel.DomainServices.Client添加到页面中(对于LoadOperation)。

using System.Linq;
using System.ServiceModel.DomainServices.Client;
using System.Windows.Controls;
using SilverlightApplication1.Web;


namespace SilverlightApplication1
{
    public partial class MainPage : UserControl
    {
        MyContext context = new MyContext();
        public MainPage()
        {
            InitializeComponent();

            context.Load(context.GetMyDataQuery("url"), loadCallback, null);
        }

        void loadCallback(LoadOperation op)
        {
            MyData d = context.MyDatas.First();
        }
    }
}