Wednesday, November 25, 2009

WCF Client

Visual Studio .NET 2008 provides a GUI interface for "Add Service Reference", which calls to svcutil.exe under the covers.


I created a new Windows Console project in VS.NET 2008 and right clicked on the project and selected "Add Service Reference", and was presented with the following dialog:





This generated the Client Proxy necessary to consume the Service. It actually created a new folder under my project called "Service References", and beneath that, an additional folder for each Service Reference.


Here is the client code that uses the generated proxy.


using System;
using WCFClient.ServiceReference;

namespace WCFClient
{
public class Client
{
public static void Main(string[] args)
{
GreetingServiceClient serviceClient = new GreetingServiceClient();
Console.Write(serviceClient.GetGreeting("Philip", "Tenn"));
serviceClient.Close();
Console.ReadKey();
}
}
}


My thoughts on this:

  • Really like being able to choose the namespace of the generated client proxy.

  • Creating the client code itself was simple ... just construct an instance of the GreetingServiceClient, and call the methods as if they were any regular class method. The details are hidden under the covers of WCF.

WCF Services

Next up: Exam 70-503: Windows Communication Foundation

Windows Communication Foundation Notes:



WCF was released as part of .NET 3.0, initially code-named Indigo. It is intended to support distributed applications and evolve from past attempts such as Remoting, Web Services, DCOM, and MSMQ.


It is focused on hosting, consuming, securing services to support distributed application.


It was enhanced as part of .NET 3.5 to support integration with Windows Workflow Foundation, as well as Web-based application support.

The "ABCs" of WCF are:

  • Address

  • Binding

  • Contract



Communication between WCF Clients and Service are done via channels. Messages are passed through the channel. The channel itself is composed of binding elements, which are stacks. The service endpoint provides a contract / interface. The WCF binding will define the channel, and there are built in bindings, such as BasicHttpBinding, WSHttpBinding, NetTcpBinding, and others.



Here is the list and definition of WCF System-Provided Bindings.

I wrote the following as my first WCF Service, based on examples in the book and on the Web.


using System;
using System.ServiceModel;
using System.Text;

namespace WCF
{
[ServiceContract]
public interface IGreetingService
{
[OperationContract]
String GetGreeting(String firstName, String lastName);
}

public class GreetingService : IGreetingService
{
public string GetGreeting(String firstName, String lastName)
{
StringBuilder greeting = new StringBuilder();
greeting.Append("Hello ");
greeting.Append(" ");
greeting.Append(firstName);
greeting.Append(" ");
greeting.Append(lastName);
return greeting.ToString();
}
}

public class Service
{
public static void Main(string[] args)
{
ServiceHost serviceHost = new ServiceHost(typeof(GreetingService), new Uri("http://localhost:8000/wcfTest"));
serviceHost.AddServiceEndpoint(typeof (IGreetingService), new BasicHttpBinding(), "");
serviceHost.Open();

Console.WriteLine("Running GreetingService, hit any key to end.");
Console.ReadLine();
serviceHost.Close();
}
}
}



The code sample above uses programmatic definition of the Service Address URI as well as the Bindings.

However, we could also declaratively define these in a web.config or app.config Configuration file.

Here is an example of an app.config file that provides the address, bindings, and exposes the Metadata Exchange information.



<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="WCF.GreetingService" behaviorConfiguration="greetingServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/wcfTest"/>
</baseAddresses>
</host>
<endpoint address=""
binding="basicHttpBinding"
contract="WCF.IGreetingService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>

<behaviors>
<serviceBehaviors>
<behavior name="greetingServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>



When I open the URL: http://localhost:8000/wcfTest, I see the following in my browser:


Passed Microsoft Exam: 70-505

Yesterday, I passed Exam 70-505: .NET Framework 3.5 Windows Forms Application Development.

In the evening, I went out and bought a book on Windows Communication Foundation. The book I got is "Essential Windows Communication Foundation For .NET Framework 3.5", by Steve Resnick, Richard Crane, and Chris Bowen. It's part of Addison Wesley's .NET Development Series.

I sat down at Borders and browsed through all the WCF books they had, and this one seemed to have the most information presented in a digestable manner.

I'm starting studies on WCF immediately.

Monday, November 23, 2009

SQL Server 2008 Express Edition

Since I'm going to be studying for an ADO.NET test soon, I figured I would need an instance of SQL Server on my home computer.

I went to Microsoft.com to download the free SQL Server 2008 Express Edition. I've used SQL Server 2005 in the past, but really haven't worked with 2008 yet.

I was presented with the following options:





I went to install "Runtime with Management Tools", since I have no need for reporting. I definitely need the runtime, and the SQL Server Management Studio that I worked with in SQL Server 2005 was pretty cool.

When I began the install process (they have a Web Installer now), I started getting an error message:





Turned out the problem was the the instance of SQL Server 2005 that was installed (probably as one of the options that I chose, though I can't recall) as part of my Visual Studio .NET 2008 Installation.

I went into Control Panel and uninstalled SQL Server 2005 Express Edition, and all of its dependencies (pretty much every program that started with the name "SQL Server"). I figured I'd uninstall the dependencies first, and finally SQL Server 2005 Express Edition last.

Turned out this was a big mistake. It basically ended up orphaning my SQL Server 2005 Express Edition, so that I couldn't fully uninstall it. So I ended up downloading and reinstalling SQL Server 2005 Express Edition SP3, and then uninstalling it.

This worked, and when I went back to install SQL Server 2008 Express, I got a new error message:





Getting closer! Just need to install VS.NET 2008 SP1.

Sunday, November 22, 2009

Deployment: ClickOnce

When reading about the Skills Measured for the Exam 70-505: Microsoft .NET Framework 3.5, Windows Forms Application Development, it appeared that a relatively high percentage of the exam (15%) was dedicated to ClickOnce.

I had done a lot of reading in the past about deployment strategies for Microsoft .NET Windows Application Deployment (ClickOnce, Installer, XCOPY), but really don't have much hands-on application, so I figured I'd begin my studies here.

Found the following starting point on MSDN about Deploying .NET Framework Applications.

Notes about ClickOnce:
  • Only supported by VB.NET and C# applications, not C++.
  • Publish Windows Forms, Windows Presentation Framework (WPF, formerly Avalon when I first started working with it), and Console Applications to a Publish Location (Web Server, Network drive, FTP Server)
  • ClickOnce Applications subject to CAS, Security Zone will depend on the Publish Location.

Passed Microsoft Exam: 70-564

I passed Microsoft Exam 70-564: Pro: Designing and Developing ASP.NET Applications Using the Microsoft .NET Framework 3.5 on Tuesday, November 17.

There really wasn't any new studying required from Exam 70-562: Microsoft .NET Framework 3.5, ASP.NET Application Development.

Things got incredibly busy at work this week (actually thought about rescheduling my exam, but I asked my manager and he said I should proceed with my exam).

So I passed it, got my Microsoft Certified Professional Developer (MCPD) distinction, and spent the rest of the week putting in tons of hours at work on optimizing SQL and performance tuning. Didn't touch my Microsoft Press books for the rest of the week.

I'm hoping to get back into it, starting with Windows Forms, when things calm down a bit at work.

Saturday, November 14, 2009

Passed Microsoft Exam: 70-562

I passed Microsoft Exam 70-562: Microsoft .NET Framework 3.5, ASP.NET Application Development on Friday (11/13/09).

Probably can't go into much detail due to the terms of the exam, all I can say is that it was painful and I walked out of the exam with a horrible migraine. Instead of writing sample code, I just crammed using the Microsoft Press book, Skills Measured, MSDN and various blogs.

Planning on going straight onto 70-564: Pro: Designing and Developing ASP.NET Applications Using the Microsoft .NET Framework 3.5

To be honest, I'm not planning to study for this test much (if at all). I have a feeling that having recently prepared thoroughly for and taken both the .NET Fundamentals and the ASP.NET App Dev exams, there should not be any new material.

Even if there is, hopefully, it should be a small enough percentage of the overall test that my preparation for the first 2 exams should be enough to pass.