1. What is WCF?

--------------------------------------------------------------------------

WCF (Windows Communication Foundation), which has code-named Indigo, is a technology by which pieces of software can communicate with one another. WCF consists of several new sets of classes added to the newer version it which enhances the power of the WCF. The WCF has been released concurrently with the Windows Vista operating system in the second half of 2006, as part of a package called WinFX.

2. Why WCF required?

-------------------------------------------------------------------------------------
It gives the feature of Web services as well as .Net Remoting. Looking into core - Windows Communication Foundation provides a software factory template for software communication, consisting of a modeling language called the Service Model, and a programming framework called the Channel Layer. One can configure the endpoints defined by an address, a binding, and a contract just by using configuration file.

3. The key components?
-----------------------------------------------------------------------------------

There are three Pillar of WCF: -

1. Productivity: - When we say productivity, we are talking about bringing together the various technologies available today for building distributed applications. It’s importance: -
- Reduce complexity by allowing us to focus on single programming model rather than learn multiple programming models.
- It allow us to use single programming model for building distributed application that communicate with one another on single machine, across multiple machines, and across the internet.

2. Interoperability and Integration:- It means that WCF enables us to build services that speak advance web services protocols(WS-*), enabling your application to communicate with other WS-* compliant services running on other platform. It’s importance: -
-The ability to communicate with application running on other platforms provides you with the flexibility you need when working in heterogeneous environment.

3. Service Orientated Development: - WCF uses attribute based programming to Define your services; you can dramatically reduce the amount of code you write To build secure, reliable service. It enables us to develop loosely coupled service And config based communication.


What we need to Start

------------------------------------------------------------------------------------------------------------
Step 1] Install .NET framework 3.0
You can download the 3.0 version of the .NET framework from the following link

http://www.microsoft.com/downloads/details.aspx?familyid=10CC340B-F857-4A14-83F5-25634C3BF043&displaylang=en

Step 2] Install Microsoft SDK for .NET 3.0
You can download the 3.0 .NET SDK from the following link

http://www.microsoft.com/downloads/details.aspx?FamilyId=C2B1E300-F358-4523-B479-F53D234CDCCF&displaylang=en

Step 3] Install Visual Studio CTP Extensions for .NET Framework 3.0
You can download the Extensions ( WCF and WPF ) for .NET 3.0 from the following link


http://www.microsoft.com/downloads/details.aspx?FamilyId=F54F5537-CC86-4BF5-AE44-F5A1E805680D&displaylang=en


These 3 steps take care of the necessary software requirements that are needed to run WCF on your machine.

I Will try to cover more about the WCF programming and developing secure services in next Articles.
I hope it will help you to get a little knowledge about the WCF.

Your comments and questions are welcome.


Why this article ?

because of this note found on the msdn’s EventInfo page:

“EventInfo is not intended to be used to raise events. An object raises events as dictated by its internal state. ”


Let’s try to raise an event with reflection …

Firstly, let’s search, but not in GetEvent, in GetField :

Type.GetField(String, BindingFlags)

String is the name of the field to get and BindingFlags a bitmask of serarching flags.

Note : To use reflecion, use “System.Reflection” using directive

Let’s try a GetField :

FieldInfo my_event_FieldInfo = this.GetType().GetField("my_event",

BindingFlags.NonPublic

| BindingFlags.Instance);

Yeah ! it’s not null ! we have now the FieldInfo of our event.

What to do now ? in a FieldInfo, we do not have something like “Fire the event”, huh

But what about “GetValue” ? The “Value” of a “FieldInfo” is the field, so the Value of an event’s FieldInfo isn’t the Event ?

FieldInfo.GetValue(object)

let’s try :

object my_event_by_reflection = my_event_FieldInfo.GetValue(this);

Download this code: 2.cs

Is null … ):

Ohhhh but, while not registered, an event is null … so, let’s try adding a handler…

Is not null ! ! Yeah, so we have our event by reflection now.

————————————————————

Note for those who just said “Why giving an object to GetValue ? And why giving ‘this’” :

1) Take a look at the first “this.getType()”

2) Deduce that it ask the Object to give you its Type, an Object knows its Type.

3) Note that a Type can’t know its Objects …

4) Finally to get a Field of your Object, you ask the Type to give it or your Object, giving a reference to your Object, here : ‘this’;

————————————————————

Now, we have an object, which is the event to call, but, how to call it ?

By reflection ? but … where to search ?

TRICK : Put a breakpoint just after the GetValue, when breaked, add a watch on “my_event_by_reflection.GetType()” and browse it… try my_event_by_reflection.GetType().GetFields() … nothing … try my_event_by_reflection.GetType().GetMethods() … browse it … OH ? What is “Invoke” ?

var my_event_invoke = my_event_type.GetMethod("Invoke");

Download this code: 3.cs

Searching how to call the Invoke … by reflection ? Invoking invoke ? Let’s try :

my_event_invoke.Invoke(my_event_by_reflection, new object[] {this, new EventArgs()} );

Download this code: 4.cs

Invoke take the instance of this type, so the object where GetType where called, and in second parameter an array of object to be given as parameter to the method called, we have to give an object and an eventArgs.

It Works ! here the full working source code :

using System.Reflection;

class Cage_en_metal

{

public event EventHandler ecraser;

public Cage_en_metal()

{

ecraser += new EventHandler(Libellule_ecraser);

fireEvent("ecraser", new EventArgs());

}

void Libellule_ecraser(object sender, EventArgs e)

{

Console.WriteLine("Splatch !");

}

void fireEvent(string handler, EventArgs eventArgs)

{

var eventInfo = this.GetType().GetField(handler,

BindingFlags.Instance

| BindingFlags.NonPublic);

if (eventInfo != null)

{

var event_member = eventInfo.GetValue(this);

// Note : If event_member is null, nobody registered to the event, you can't call it.

if (event_member != null)

event_member.GetType().GetMethod("Invoke").Invoke(event_member, new object[] { this, eventArgs });

}

}

}

Add below code to your resources or the style page.
&lt:Style x:Key="GlassBorderStyle" TargetType="Border"&gt:
&lt:Setter Property="BorderThickness" Value="2"/&gt:
&lt:Setter Property="Padding" Value="5"/&gt:
&lt:Setter Property="Background"&gt:
&lt:Setter.Value&gt:
&lt:LinearGradientBrush EndPoint="0.75,1" StartPoint="0.25,0"&gt:
&lt:GradientStop Color="#33FFFFFF" Offset="0"/&gt:
&lt:GradientStop Color="#C0FFFFFF" Offset="0.287"/&gt:
&lt:GradientStop Color="#4011322D" Offset="0.683"/&gt:
&lt:GradientStop Color="#33FFFFFF" Offset="1"/&gt:
&lt:/LinearGradientBrush&gt:
&lt:/Setter.Value&gt:
&lt:/Setter&gt:
&lt:Setter Property="BorderBrush"&gt:
&lt:Setter.Value&gt:
&lt:LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"&gt:
&lt:GradientStop Color="#5811322D" Offset="0"/&gt:
&lt:GradientStop Color="#3EFFFFFF" Offset="0.25"/&gt:
&lt:GradientStop Color="#FFFFFFFF" Offset="0.5"/&gt:
&lt:GradientStop Color="#3EFFFFFF" Offset="0.75"/&gt:
&lt:GradientStop Color="#BFFFFFFF" Offset="1"/&gt:
&lt:/LinearGradientBrush&gt:
&lt:/Setter.Value&gt:
&lt:/Setter&gt:
&lt:Setter Property="Effect"&gt:
&lt:Setter.Value&gt:
&lt:DropShadowEffect BlurRadius="3" ShadowDepth="3" Opacity="0.5"/&gt:
&lt:/Setter.Value&gt:
&lt:/Setter&gt:
&lt:/Style&gt:

now create a button and apply the resource of that Glass Border.
&lt:Border x:Name="GlassBorder" Height="100" Width="250" CornerRadius="10" Style="{StaticResource GlassBorderStyle}"&gt:
&lt:Button Content="Glass Border Style"/&gt:
&lt:/Border&gt:

There are lots of way's to Reduce the Size of Xap file. like.

  1. Just put Multimedia files like images & video at client bin folder where the xap file is.
  2. this ways you will reduce the size of XAP file & take a fast loading.
  3. And also we can reduce size of XAP.. go to sliverlight project in Application ,Right click on it go "properties" see an option called -"Reduce Xap size by using appplication library chaching"
  4. We can move all the dlls (system dlls) out of the XAP files. They will be loaded on demand and will be downloaded from microsoft website/website of your wish.
  5. Split silverlight project into multiple silverlight projects. Load them when you need it. This way you can load what you need and also you save bandwidth.

A basic xap file in silverlight will have an assembly related to specific code for the application, an application manifest file and any additional assemblies need to run the application. At a minimum, two files are needed, the application manifest file and the application assembly. For example:

  • AppManifest.xaml
  • MySiilverlightproject.dll
Once you have created the .xap file, the Silverlight plug-in downloads the file and runs it in a separate work space.

A .xap file is used to contain and transfer the assemblies and resources of a managed code application. This managed code application must be run within the Silverlight 2 browser plug-in.

Every dot net application is complied with the dot net compilers and deployed in dll. (Dynamic Link Library.) same in the Silverlight all deployment of Silverlight is done in the dll. but the deployment of Silverlight are compressed into a xap file. which is the output of the silverlight project.
the XAP file is actualy a ziped files which as all external resource dll into a zipped files

  1. Silverlight uses a particular implementation of a XAML parser, with that parser being part of the Silverlight core install. In some cases, the parsing behavior differs from the parsing behavior in Windows Presentation Foundation (WPF), which also has a particular implementation.
  2. WPF(Windows Presentation Foundation) use for the Desktop Application and SilverLight is use for Web Applications (Rich Internet Applcaions).
  3. Both Have their seperate XAML parser.

  1. Silverlight is a new cross-browser, cross-platform implementation of the .NET Framework for building and delivering the next generation of media experiences and Rich Interactive Applications(RIA) for the web. It runs in all popular browsers, including Microsoft Internet Explorer, Mozilla Firefox, Apple Safari, Opera. The plugin required to run Silverlight is very small in size hence gets installed very quickly.
  2. It is combination of different technolgoies into a single development platform that allows you to select tools and the programming language you want to use. Silverlight integrates seamlessly with your existing Javascript and ASP.NET AJAX code to complement functionality which you have already created.
  3. Silverlight aims to compete with Adobe Flash and the presentation components of Ajax. It also competes with Sun Microsystems' JavaFX, which was launched a few days after Silverlight.
  4. We can also say It is nothing but it has the ability to web applcation is exhibits like the Desktop Application (RIA - Rich Internet Application )which is Cross Browser , Cross Plateform ,Silverlight Aplication can runs on any browser but u neet to installed the Silverlight Plug-Ins which is free to run the applicaion on your browser.