Silverlight: Llamada a servicios WCF (no RIA) - ¿Modelo asíncrono, modelos de entidad y anotaciones de datos?

I have been following some examples of RIA services and although a great concept, i am locked into using a WCF Service (not RIA) as it is also used by other clients like WPF, and asp.net.

THe good thing about RIA was that the ASYNC calling of the service was hidden but with WCF i presume this is not the case so how is it possible to call a WCF Service from silverlight. Add service Reference? and then i presume i have to call and wait for a callback?

Any tutorials on this?

This is a real shame for me as i would have liked to use RIA services.

The other doubt i have that comes to mind is the use of Entity models and data annotations. In ria this was really easy, but if i am using standard wcf services then i presume that the entity classes (actually i am using ENtity framework) will arrive on the client (silverlight) because i do Add Service Reference? Am i correct here?

WIth Data annotations, ria automatically sent the entity classes with the data annotations from the server (ria) to the client (silverlight) - but what is the case with standard WCF services.

So currently i believe that i need a silverlight clietn app and "NO" ria services but i basically would call to wcf services.

The question that arrises now is should i use a mix of RIA and WCF services? silverlight calls RIA and then RIA calls WCF Service...

I would really apprecaite any feedback as i am a little lost of the right direction to take... With ria - it was so simple :-)

Gracias por adelantado

preguntado el 08 de enero de 11 a las 17:01

You can do this. We've just (well a couple of months ago) converted all our WCF services to RIA services so I don't have the code to hand (coupled with the fact I'm not at work) to show you an example. -

Thanks Chris, thanks for the confirmation... Yes this is still a grey area for me. I love RIA services but i just don't have the option of using them. -

The other idea i had, although might be completely wrong :-) was to create a local (local to silverlight webapp) wcf service SVC so that silverlight can call this and if needed i can then call the wcf service for data etc. I would use the local wcf service for standard business logic type stuff that doesn't need to call my external WCF service.. Does that make sense? Or a waste of resources? -

1 Respuestas

When you add a service reference to the Silverlight project, the client code will be auto-generated for you, i.e. you will get a class of the form:

public partial class AdventureWorksEntities : global::System.Data.Services.Client.DataServiceContext

From then on, you can use the DataServiceCollection class to in order to hide all the client-server logic under the hood. For example:

using DataServices.EmployeesService;
using System;
using System.Data.Services.Client;
using System.Windows.Controls;

namespace DataServices
{
    public partial class MainPage : UserControl
    {
        private AdventureWorksEntities context = new AdventureWorksEntities(new Uri("Services/EmployeesService.svc", UriKind.Relative));

        public MainPage()
        {
            InitializeComponent();

            DataServiceCollection<Employee> data = new DataServiceCollection<Employee>();
            this.dataGrid.ItemsSource = data;
            data.LoadAsync(context.Employees);
        }
    }
}

Creo que este artículo del proyecto de código can get you started.

Respondido el 10 de enero de 11 a las 13:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.