views:

94

answers:

1

Helo!

I need to write a RIA service to call Java webservices from Silverlight 3.0 app. I'm testing how stuff works and in my Web app I have a MyData class which has 2 properties (int ID, string Text):

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

        public string Text { get; set; }
    }
}

Then I wrote simple 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();
        }
    }
}

How can I get data into my SL app? Now I have this:

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

I called and load but nothink worsk (exceptions, or nulls)...

I had Invoke annotation but MyData is not TEntity and I can't use Strings or other simple types as well... :/ I'm reading and reading posts and nothing works like it should..

Any help would be really appreciated.

Thank you!

A: 

Your code looks good on the server. You will want to move the context outside of the MainPage constructor and add a callback to your load operation. Also make sure to add the System.ServiceModel.DomainServices.Client using to the page (for 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();
        }
    }
}
JosephC