Tuesday, October 21, 2008

Silverlight 2 Grid with Silverlight Enabled WCF Services

With ref. to my previous post on Silverlight 2 Grid : LINQ to SQL + WebServices, I would like to just add this post as a patch to it [In our terms we call it “Service Pack” :) ]

Astoria I am working on it, so may be I will drop more light on that part around this weekend [Diwali festival preparation is on head]

Microsoft given a wonderful template as “Silverlight enabled WCF Service”, well extention is still svc as it was for WCF and it is for Astoria too [Entity Framework ADO.NET services] which comes with SP of Visual Studio 2008

See the pictures below :


From above fig. SLSrv.svc is our Silverlight enable WCF service, See the below diagram so that you will get idea how that is there :


What I like most about Silverlight enable-WCF services is they are much more simple than WCF and they have unique flavor of old ASMX services, so you may not find an separate Interface –class file to implement the Operation Contracts, All goes in one file which is good thing from developers point of view, especially newbies often get confuse with WCF for their initial days of development.

So, rest all part is same like adding ref., creating proxy etc. code will look like follows :

namespace SLEnableWCF.Web
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class SLSrv
        public List<Cust> DBConnect()
            MyDatabaseDataContext db = new MyDatabaseDataContext();
            var temp = from cust in db.Custs
                       where cust.CustName.Length > 0
                       select cust;
            return temp.ToList();
        // Add more operations here and mark them with [OperationContract]

This is how we can go ahead and add whatever no of Operation Contract here with their signature and implementation.

This makes life easy and again XAML.cs code will be as is like it was earlier, like to fire completed event and calling async() method.

I leave this part below without any explanation for my users, sort of excercise for them :

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

Well, if you feel that you want some more differences between this Silverlight enable service and other services, A good post is here :


So, I hope now you will drop WCF weapons and pick up this new one, I will be back with tons of new things like Astoria,LINQ to XML and offcourse Silverlight !


No comments: