News

 

I wanted to make two of 3.5 framework additions to work together. I decided to make a WCF Web Service and LINQ. I had a few pitfalls with the LINQ. So, I created it in SQL first, then I re-did it in using  LINQ.
Creating a WCF web service is fairly simple. Open the newest and greatest version of Visual Studio to date; VS 2008. File, New, Web Site and highlight WCF Service. Choose how you want it to work, meaning file system or point to a web; I choose file system and uploaded to my web site. After you create the default WCF Service you should open IService.cs and the Service.cs; both located in the App_Code folder. Starting with the Interface you will notice two contracts already there;
[OperationContract]
    string GetData(int value);
 
[OperationContract]
    CompositeType GetDataUsingDataContract(CompositeType composite);
At this point I added a new contract.
[OperationContract]
    string AllEmployees();
That was pretty much it for the Interface.
Next, I created my data classes. This is the very heart of LINQ. I added a new item to my project, LINQ to SQL Classes. This added a blank page where I simply dragged the tables in I wanted to reference. Pretty simple!!!
Now it was time for the backend. I opened Service.cs to add a few name spaces;
using System.Configuration;
using System.Data.Linq;
The configuration name space allowed me to point to a database. The System.Data.Linq name space allowed me to use Table<>.
Next I made a public method named AllEmployees() and added the following code;
public string AllEmployees()
    {
        DataClassesDataContext db = new DataClassesDataContext(ConfigurationManager.ConnectionStrings["ASPNETDBConnectionString"].ConnectionString);
        Table<Employee> Emps = db.GetTable<Employee>();
 
        var query =
            from e in Emps
            select e;
 
        string result = "<Employees>";
 
        foreach (var e in query)
        {
            result += "<Employee><EmployeeID>" + e.EmployeeID + "</EmployeeID><LoginName>" + e.LoginName + "</LoginName>" +
            "<FullName>" + e.FullName + "</FullName><Department>" + e.Department + "</Department></Employee>";
        }
 
        result += "</Employees>";
 
        return result;
    }
When working in SQL most of us create our connection object first.  Then we create our command object, then we do some binding and move on to either a adapter object or a reader object. In LINQ the connection object and the command object are summed up in DataContext object – which references the dbml file created. In my case the default name DataClasses (DataClassesDataContext.dbml). In any event this one object took the place of the SQL Connect and command objects.  The next line creates a table enumeration object; basically a pointer to the table. Then instead of a standard SQL statement LINQ statements use the new var type that basically holds our data. The foreach look simply reads through the var type and in my case builds xml to be returned in the service.
The next thing I need to learn is sending that var type directly to a DataSet!!!
This pretty much sums up the WCF service – So I uploaded it to my site…
Consuming the service was just as simple
I created a windows form; I added the service reference I just built on my web site. I added a datagrid control and a button to the form. In my button click event I added the following code;
private void button2_Click(object sender, EventArgs e)
        {
            ServiceReference1.ServiceClient sc = new WindowsFormsApplication1.ServiceReference1.ServiceClient();
 
 
            WindowsFormsApplication1.ServiceReference1.IService Proxy = sc.ChannelFactory.CreateChannel();
 
            string list = Proxy.AllEmployees();
 
            StringReader sr = new StringReader(list);
            DS.ReadXml(sr, XmlReadMode.InferSchema);
            DS.AcceptChanges();
 
 
            try
            {
                DS.Tables[0].Clear();
            }
            catch { }
 
 
            this.dataGridView1.DataSource = DS.Tables[0];
 
        }
The first thing I did was create a object that references the WCF service. Then I created an object that references the WCF Interface. Next I call the AllEmployees() contract on the Interface, which calls the public string method AllEmployees().  Then convert the string back to XML and point the data source of the datagrid…
What I learned was WCF is just as simple as a regular web service. WCF is all about the contract and thus the Interface. LINQ is just plain simple!
If anyone knows how to send LINQ var to a DataSet – please let me know!
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

 

This week, I played with Expression Blend, started using Visual Studio 2008 and had another great meeting with Philly Dot Net User group.
Expression Blend:
I’ve built many flash applications. Microsoft has handled some of the complaints I’ve always had with flash. You can program to it!!! Flashes ability to develop beautiful sites is excellent. But the ability to manipulate the output via code is non-existent. The first thing I did is followed a couple of the great training videos from http://www.microsoft.com/Expression/kc/resources.aspx?product=blend&type=video . if you haven’t played with Expression, download a trial or get it from your MSDN subscription; It’s great. Once you start working with it you will realize Silverlight is without a doubt going to change the face of web sites. Move over Flash – Silverlight is here!
VS 2008:
I reformatted my laptop in anticipation of the Visual Studio 08 release. I checked MSDN every day since I reformatted. I started downloading at 10:30 AM by 2:00 PM I was installing it. It took a while to install. As a matter of fact, I drove home with my laptop on and installing. After it was up and running the first thing I did is create a new WCF host. I’ve never been a fan of templates, I was surprised to see when I created a new WCF project that Interface with automatically added – WOW! 
If you didn’t download it yet – DO IT. If you are not an MSDN member, it is well worth the cost. Or you can just buy VS 2008.
Philly.Net User Group:
This was meeting was a special meeting – The theme was “6 year anniversary party Featuring 15 minutes of Fame!
The meeting consisted of;
Marc Ziss, ZConsulting Using Subsonic to build a Data Access Layer and Admin App
Mark Magliocco, Consultant Mentoring 101
Steve Andrews, RDA Consulting Building a Visual Studio Debugger Visualizer
Andy Schwam, It's Time To Learn LINQ
Travis LaBorde, TelerX XML is awesome in VB9!
Brian Donahue, Pigeon Moon ALT.NET -The Pursuit of Happiness (on the .NET Framework)
Danilo Diaz, Microsoft How to be more valuable
David Mann, KDC Holdings WSS as a Web Application Platform
Mitch Ruebush, INGDirect Build a Game in 15 Minutes with XNA and C#  - Mitch had a family emergency so;
Rob Keiser – Gave a lesson on  Power Shell – Way to go Rob! 
Bill Wolff, Unisys Corporation Microsoft Developer Roadmaps
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

 

Another great MSDN session in PA. As usual Lindsay Rutter gave 3 great courses. The theme this time was the web.

Session 1 was a great example of Visual Studio 2008. I hadn't seen it yet. I was very happy to see we can now pick which framework we are coding to. But even more impressive is managed JavaScript!   The idea of being able to walk through JavaScript instead of testing live is going to bring scripting to an entire new level!

Session 2 was a lesson in using LinQ and what MS is coining as A New Paradigm for Data Development with Web Based Data Services. Basically the new paradigm is the way DBA's have done it for years. I guess it's new for developers - lol. Don't get me wrong there are some new cool features but I'm not sure if this method is meant to work with 10,000 lines of data from 5 different data sources. Time will tell...

Session 3 was an example of web development with Silverlight, C# and AJAX. MS is going all out with Silverlight. I program action script files. One of the biggest complaints I have had is there is no efficient way to integrate flash with any other systems. MS is allowing Silverlight to be 100% dynamic. We can program output and input  with C# and JavaScript.

I've recently met a developer that programs in classic ASP. His ASP skills are great. He keeps saying Ajax, why? "I can do it in VB script/ASP."  The funny thing is after watching how Silverlight gets data from JavaScript which gets it dataset from C# and seeing the classic <% var %> symbols, I can't help to think even though he is behind the times, he is partially right... Argh!

 

Problem BadFix = new Problem();

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati