locked
How to consume wcf service in Silverlight using MVVM Pattern RRS feed

  • Question

  • Hi

     

    I have a WCF Service with 3 operational contract named

    1)Add Employee(Employee e)

    2)GetEmployee(intEmpid)

    3)DeleteEmployee(int Empid)

     this service is hosted in a server.

     

    all i need is how to create a silverlight application to consume the service using MVVM Model.

    where i need to add the reference of that service in Model or in ViewModel or in some other project.

     

    Thursday, December 3, 2009 9:12 AM

Answers

All replies

  • Are you using anything like Prism / Unity?

    Thursday, December 3, 2009 9:31 AM
  • You can take a look at this post, http://weblogs.asp.net/fredriknormen/archive/2009/11/30/silverlight-4-mvvm-with-commanding-and-wcf-ria-services.aspx it's about the MVVM, it will use Commanding and SL 3 don't have it, but you can see how you can for example call a WCF service within a ViewModel.. The example uses WCR RIA Services, but just replace the RIA Services loading to a call to one of your WCF methods.

     

    Edit: Missed the pointer ;)

    Thursday, December 3, 2009 9:56 AM
  • Yes iam using Prism

     

    Friday, December 4, 2009 4:06 AM
  • The Compostite Application Guidance that comes with Prism shows some basic examples of resolving a service but nothing really on what goes on behind the scenes for connections etc.

    Thankfully there are quite a few good resources when it comes to consuming WCF within Prism.

    http://www.codeplex.com/SDMS

    http://www.netfxharmonics.com/2008/11/Understanding-WCF-Services-in-Silverlight-2

    For anything Silverlight/WCF you can always go direct to the source:
    http://blogs.msdn.com/silverlightws/

    Friday, December 4, 2009 4:35 AM
  • hi in the blog you have mentioned.

    Is the client implementing MVVM  Model to consume the wcf service

    Friday, December 4, 2009 4:54 AM
  • The first link has a webcast about consuming wcf in Prism which is what you are after.

    The blog is more a great overview of the various features / issues you get with SL & WCF. Well worth saving in your favourites or setting up a feed.

    Friday, December 4, 2009 4:58 AM
  • hi

    I have the following operation contract in wcf service hosted in XYZ Server

    [ServiceContract]
        public interface IEmployee
        {
            [OperationContract]
            EmployeeEntity GetEmployeeById(int EmpId);

            [OperationContract]
            int AddEmployee(EmployeeEntity empEntity);

            [OperationContract]
            List<EmployeeEntity> GetAllEmployees();
           
        }

     

    am consuming it in Prism framework.

    when i do the add reference the proxy generated is in form of ASync

    now how can i do MVVM in the Prism infrastructure

    Friday, December 4, 2009 9:21 AM
  • Take a look at this to abstract the service implementation and get rid of that pesky clientconfig file:

    http://csharperimage.jeremylikness.com/2009/07/abstracting-wcf-service-calls-in.html

    Then take a look at this so that your view model simply deals with actions and entities, rather than having to understand asynchronous service calls or have an affinity to how the service actually returns the value:

    http://csharperimage.jeremylikness.com/2009/12/simplifying-asynchronous-calls-in.html

    Monday, January 4, 2010 10:19 AM
  • hi ..my question is

    i have a datagrid,i need to bind the data using silverlight application,mvvm,edm,wcf...

    i did the abve by using edm,wcf,silverlight...but not able to implement it in mvvm can u guys pls help me out..iam a beginner in silverlight..

     

    Wednesday, September 29, 2010 9:26 AM