none
My problem - is MVVM the answer?

    Question

  • Hi There,

    Forgive my wet-behind-the-ears question here - I'm new to Silverlight, and actually anything other than code that is pure data manipulation. Not sure if MVVM is what I'm looking for ...

    I'm trying to build a silverlight application that shows data pulled from a Microsoft CRM system. My challenge is that I need to write in .NET to get the data from the CRM system - I need .NET assembly references to access the CRM data (not really a web-service, as they are dlls). Then, I need to get that data and pass it to Silverlight.

    I tried just using the WEB project that they give you with a new Silverlight project, but I can't seem to share classes between the 2 projects properly - any code that can access CRM will break when I try to link it to my Silverlight project (because of the using statements for the .NET assemblies, which Silverlight can't recognize). If I use conditional compiling directives to cut out the using statements and code that doesn't compile in Silverlight, it also cuts that code out of the run-time (at least in de-bug mode).

    Can anyone give me some guidance? How can I connect my server-side program that pulls data from CRM to Silverlight?

    Thanks,

    Andy

    Thursday, July 15, 2010 10:00 PM

Answers

  • MVVM really has nothing to do with solving your problem.

    The problem is getting data from the CRM to the Silverlight client. That can be done a variety of ways. MVVM addresses more of the separation of concerns on the client side and how you structure and maintain your application. 

    To fully understand the solution, you need to really look at Silverlight as a client-server application, with Silverlight being the client. 

    First question: where does the Microsoft CRM system live relative to the Silverlight client? If it is installed on my laptop, then it is local to me, and there may be a way to connect the two. However, more likely, you have a user on a browser on machine "A" while the Microsoft CRM is over on machine "B". In that case, you must have some sort of method for connecting the two, and this will likely be a service.

    Even if the DLLs themselves are not services, you can build regular .NET server code that interfaces with them, then exposes the information via a web service.

     So your architecture will likely look like this:

    [CRM Layer]

    [DLL Interfaces]

    [Your .NET Layer that talks to CRM on the Server]

    [Web Service Front End]

    [-- the Internet --]

    [Silverlight Web Service Client Proxy]

    [Your Silverlight Application]

    Does that make sense and help you drive closer to your goal?

    Thursday, July 15, 2010 11:17 PM
  • So the answer is, "Yes" you would place a service yourself in front of the .NET interactions you are creating.

    As for the Silverlight proxy, this is something automatically generated either when you add a service reference or when you create a WCF RIA project. You could certainly use WCF RIA for this.

    Take a look at the sample application:

    http://code.msdn.microsoft.com/RiaServices

    The POCO one shows how to connect WCF RIA to classes without having an underlying database.

    Here is my blog post on it, may be a little dated as it was a previous version, but it captures the essence:

    http://csharperimage.jeremylikness.com/2009/11/ria-poco-domainservice-with-existing.html

    Since you are working with a list, you'll also be interested in this post and the responses:

    http://forums.silverlight.net/forums/p/191588/442374.aspx 

    Best of success! 

    Friday, July 16, 2010 11:10 AM
  • You are correct ... you'll need to determine *what* you will be sending across the wire to expose in the service, but how you get that *what* is, in your case, going to involve connecting to the classes you have. 

    Friday, July 16, 2010 2:01 PM

All replies

  • MVVM really has nothing to do with solving your problem.

    The problem is getting data from the CRM to the Silverlight client. That can be done a variety of ways. MVVM addresses more of the separation of concerns on the client side and how you structure and maintain your application. 

    To fully understand the solution, you need to really look at Silverlight as a client-server application, with Silverlight being the client. 

    First question: where does the Microsoft CRM system live relative to the Silverlight client? If it is installed on my laptop, then it is local to me, and there may be a way to connect the two. However, more likely, you have a user on a browser on machine "A" while the Microsoft CRM is over on machine "B". In that case, you must have some sort of method for connecting the two, and this will likely be a service.

    Even if the DLLs themselves are not services, you can build regular .NET server code that interfaces with them, then exposes the information via a web service.

     So your architecture will likely look like this:

    [CRM Layer]

    [DLL Interfaces]

    [Your .NET Layer that talks to CRM on the Server]

    [Web Service Front End]

    [-- the Internet --]

    [Silverlight Web Service Client Proxy]

    [Your Silverlight Application]

    Does that make sense and help you drive closer to your goal?

    Thursday, July 15, 2010 11:17 PM
  • Hi Jeremy,

    Thanks for the response - I actually was reading your blog before posting last night in my search for an answer!

    That does help. I've been struggling to connect my .NET code and my Silverlight code. I've been writing this type of CRM code for several years, but have never tried to use it in Silverlight before.

    The CRM data is on a server and is called via a web service, although, as you noted, it's not an asmx or wsdl service that I use in my code, it's via dlls. I've already done the work of retrieving the data and have it in my .NET code, in a List<>, and my last step is to get that into Silverlight.

    So in your architecture, you show:

    [Web Service Front End]

    [-- the Internet --]

    [Silverlight Web Service Client Proxy]

    Is the web service front end just a web service that I build manually? And I'm not sure where to look for the Silverlight Web Service Client Proxy. Can you point me to some documentation or tutorials? Does this involve WCF or RIA?

    Thanks Jeremy!

    Friday, July 16, 2010 10:19 AM
  • So the answer is, "Yes" you would place a service yourself in front of the .NET interactions you are creating.

    As for the Silverlight proxy, this is something automatically generated either when you add a service reference or when you create a WCF RIA project. You could certainly use WCF RIA for this.

    Take a look at the sample application:

    http://code.msdn.microsoft.com/RiaServices

    The POCO one shows how to connect WCF RIA to classes without having an underlying database.

    Here is my blog post on it, may be a little dated as it was a previous version, but it captures the essence:

    http://csharperimage.jeremylikness.com/2009/11/ria-poco-domainservice-with-existing.html

    Since you are working with a list, you'll also be interested in this post and the responses:

    http://forums.silverlight.net/forums/p/191588/442374.aspx 

    Best of success! 

    Friday, July 16, 2010 11:10 AM
  • Thanks Jeremy! I appreciate your guidance. I'll check those resources out.

    Best,

    Andy 

    Friday, July 16, 2010 11:14 AM
  • Jeremy,

    your answer is very complete and of incredible Value. thank you


    Andy,

    you can look into XRM, as well

    http://msdn.microsoft.com/en-us/library/ee830281.aspx


    Regards


    Friday, July 16, 2010 12:35 PM
  • Hi Oscar,

    That's exactly what I'm doing! I'm using the assemblies from the new microsoft.xrm SDK folder. 

    Thanks,

    Andy

    Friday, July 16, 2010 1:06 PM
  • Jeremy,

    Your blog post is fantastic. It's given me everything I need to know. Can you clarify one statement? Discussing the process of getting your data access layer into your domain service, you say you can do a factory, Constructor Injection, MEF, and then you say:

    ... or maybe you just want to new it up. It's up to you. 

    I'm working with a set of classes generated through code that represent the objects in the CRM db. One of the objects is a "DataContext" class that defines actions that can be performed on the other classes, which represent the db objects. There's a "Save" method that commits changes such as "AddToaccounts" (Example below) to the db.

    When you say "new it up" - can I take this data context class and put it in the Domain Service, and will its availability allow me to do what I need to do to call my CRM data into the Silverlight app?

    Thanks Jeremy!

    /// <summary>
      /// Adds a new 'Entities.account' entity to the set of <see cref="Entities.account"/> entities.
      /// </summary>
      public void AddToaccounts(global::Entities.account entity)
      {
       this.AttachTo("accounts", entity);
       this.AddObject("accounts", entity);
      }

    Friday, July 16, 2010 1:33 PM
  • You are correct ... you'll need to determine *what* you will be sending across the wire to expose in the service, but how you get that *what* is, in your case, going to involve connecting to the classes you have. 

    Friday, July 16, 2010 2:01 PM