Archive for June, 2010

Optional Parameters in C#

With the release of .NET 4.0 C# programmers are now able to created methods with optional parameters like VB programmers doing. Optional arguments are widely used in VBA for long time. Although they make life a little bit easier for programmers (you don’t have to repeat default values in your method calls).

Code Snippet
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace optionalParameters
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             OptionalParameterTest t = new OptionalParameterTest();
  13.             Console.WriteLine("Optional Parameter :  {0}", t.OptionalParameter("One"));
  14.             Console.WriteLine("Optional Parameter :  {0} ", t.OptionalParameter("One1", "Two1"));
  15.             Console.WriteLine("Optional Parameter :  {0} ", t.OptionalParameter("One1", "Two1","three1"));
  16.             Console.WriteLine("Optional Parameter :  {0} ", t.OptionalParameter("One1", "Two1","Three1","Four1"));
  17.             Console.ReadLine();
  18.  
  19.         }
  20.  
  21.     }
  22.     public class OptionalParameterTest
  23.     {
  24.         public string OptionalParameter(string  one, string two = "Two",string three="Three",string four="Four")
  25.         {
  26.  
  27.            
  28.             return one + "  " + two + "  " + three + "  " + four;
  29.         }
  30.     }
  31.  
  32. }

Optional Parameters

WCF Messages

Applications written using Windows Communication foundation communicate through messages. WCF uses SOAP messages, formatted in XML as SOAP messages.

WCF Message

Lets discuss each of the section in detail

SOAP Envelope is outer most section of WCF message. It acts as a container for WCF header and body. A SOAP envelope contains several pieces of key information in the form of elements. They include the following:

  • The name of envelope
  • Namespace name : The namespace name must be “http://www.w3.org/2003/05/soap-envelope”.
                            • An optional <header> element: SOAP header is a collection of one or more than one header block. A SOAP message can contain zero or more than one header block. If a header is included, it must be the first child element of the envelope element. Header is  good place to put optional information related to message. Any child element of header element is called “Header Blocks”.  The following code sample illustrates the basic format for including a message header:
                              <env:Envelope xmlns:s=”http://www.w3.org/2003/05/soap-envelope” xmlns:a=”http://schemas.xmlsoap.org/ws/2004/08/addressing”>
                              <env:Header>
                              </env:Header>
                              </env:Envelope>
  • A required body element. : The SOAP body is a collection of data items to be used at a specific target (SOAP receiver). Like the SOAP header, a message can contain zero or more bodies.

WCF Messaging Programs

In WCF ,following type of applications can send and receive messages

  • Client: Client is a program that initiates a communication via sending a message
  • Service: Service is program that respond to a message. Service perform predefined activities once it receives a message. A service never initiates a communication. While processing request , if the service call some other services than this concept is called “Service chain”. Here the service is acting as client and service has initiated the communication in response to incoming message.

Messaging Patterns

Messaging patterns, basically describe how programs should exchange messages. There are three basic messaging patterns that programs can use to exchange messages. Those patterns include the following:

  • Simplex : The Simplex message pattern is simply a one-way communication from Program A to Program B. No response is generated by Program B, thus causing the one-way communication. Simplex messaging suffers from short term memory loss. When the client sends the message, it has no idea it sent a message because it is not expecting a response.
  • Duplex: In duplex pattern client and service programs communicate openly and exchange information in both directions.
  • Request-Reply: Request-Reply messaging pattern doesn’t allow bi-directional communication to happen freely. In this pattern, the client sends a response and then waits for reply. The service doesn’t communicate anything until it receives a message.

AppFabric Dashboard Overview

AppFabric has this great new Dashboard that gives you insight into what is happening with your services and workflows. In this video, Senior Programming Writer Michael McKeown shows you what the Dashboard can do for you.

Get Microsoft Silverlight

How to Run Java Apps in Windows Azure

A video is posted on MSDN showing how developers can use Windows Azure platform to run Java Applications. In the video, Scott Golightly creates a simple Java application that runs under Apache Tomcat, and then shows how that can be packaged up and deployed to the Windows Azure development fabric.

About this Video

Windows Azure in an open platform. This means you can run applictions written in .NET, PHP, or Java. In this video Scott Golightly will show how to create and run an application written in Java in Windows Azure. We will create a simple Java application that runs under Apache Tomcat and then show how that can be packaged up and deployed to the Windows Azure development fabric.

ADO.NET Data Services

WCF Data Services (formerly ADO.NET Data Services[1], codename "Astoria")[2] is a platform for what Microsoft calls Data Services. It is actually a combination of the runtime and a web service through which the services are exposed. In addition, it also includes the Data Services Toolkit which lets Astoria Data Services be created from within ASP.NET itself. The Astoria project was announced at MIX 2007, and the first developer preview was made available on April 30, 2007. The first CTP was made available as a part of the ASP.NET 3.5 Extensions Preview. The final version was released as part of Service Pack 1 of the .NET Framework 3.5 on August 11, 2008. The name change from ADO.NET Data Services to WCF data Services was announced at the 2009 PDC.