Wednesday, June 3, 2009

WCF Basics

What is WCF?


WCF is a unification technology, which unites the following technologies:-

• NET remoting

• MSMQ

• Web services

• COM+.





The above terminologies are the core on which SOA stands. Every service must expose one or more ends by which the service can be available to the client. End consists of three important things where, what and how:-

• Contract (What)

Contract is an agreement between two or more parties. It defines the protocol how client should communicate with your service. Technically, it describes parameters and return values for a method.

• Address (Where)

An Address indicates where we can find this service. Address is a URL, which points to the location of the service.

• Binding (How)

Bindings determine how this end can be accessed. It determines how communications is done. For instance, you expose your service, which can be accessed using SOAP over HTTP or BINARY over TCP. So for each of these communications medium two bindings will be created.


The Important Principles of SOA?


WCF is based on SOA. SOA is based on four important concepts:-

• Boundaries are well defined

In SOA, everything is formalized. The client who is consuming the service does not need to know how the implementation of the service is done. If you look at some old methodologies of communication like DCOM. Any changes at server level the client also has to change. Therefore, the server and client implementation was so much bound that changes need to be done at all places. In SOA, the rule is if you do enhancement you do not need to change anything at the client. SOA based application only understands that there is an end point, contract, and bindings.

Note: - Just to clarify shortly about end point and contract. Any SOA service is exposed through an end point. End point defines three important aspects What, Where and How.


• Services evolve

Change is the law of nature and services will evolve. In SOA, services can be versioned and you can host those services in new ends. For instance, you have a service called as “Search Tickets (Ticket Number) “which gives details based on Ticket Number and its exposed on end point “ep1”. Tomorrow you want make your Search Tickets service more useful by also providing an extra option of allowing him to search by passenger name. Therefore, you just declare a new end “ep2” with service “Search Tickets (Ticket Number, Passenger Name)”. So the client who is consuming the service at end ep1 continues and at the other end, we have evolved our service by adding new ends ep2.

• Services share only schemas and contracts

Services use Schemas to represent data and contracts to understand behavior. They do not use language dependent types or classes in order to understand data and behavior. XML is used to define schemas and contracts. Due to this, there is not heavy coupling between environments.

• Service compatibility is policy based

Policy describes the capabilities of the system. Depending on policies, the service can degrade to match the service for the client. For instance your service needs to be hosted for two types of client one which uses Remoting as the communication methodology while other client uses DCOM. An ideal SOA service can cater to both of them according to there communication policies.


A Step by Step WCF Small Programme For Beginners

Abstract

In this article, i am gonna show you a small Addition programme using WCF. After going through this snippet, reader gets a clear and basic understanding of the WCF programme.

Introduction

WCF(Windows Communication Framework) is a unification technology, which unites the following technologies:-• NET remoting• MSMQ• Web services• COM+. It is based on SOA(Service Oriented Architecture). Read basic before go through this article.

Code Snippet
(Service/Server Side)

Steps Involved:-
Step 1: Open VS2008 , create project and choose "Windows Service Application" just give any name to your project. I named it "MyService".

Step 2: You will see the solution window, in that open "IMyService.cs". In that you will see [ServiceContract] below this your interface name is declared. There after you'll see [OperationContract] your function contract should be define here. The implementation of the function will be define in "MyService.svc.cs" As provided in the picture.




Step 3: Open "MyService.svc.cs" and write code here. As i have written code for my "addfunction". You can write your code inside your function. The picture is shown below.

Step 4: This is most important step. In this we are declaring the end point. Inside the we can define end point, as shown in picture end point is defined automatically. we can also define it by programme.


Step 5: Save the project and run it. This will Display like this. Copy the address from explorer address bar.



Code Snippet
(Client Side)
Let the server service run(the above page).

Step 1: Open a web application in another VS2008 and right click on solution name and then go to "Add Service Reference" one window will open paste the previously copied link to the address bar and press GO. Then the service will appear in service section then press OK. The service reference will appear in solution explorer as below.


Step2: Now add one button on the default page, then double click on button you'll be in code behind section. Here create the object of the service which appeared in the solution explorer. Something like this.

protected void Button1_Click(object sender, EventArgs e)
{
ServiceReference1.MyServiceClient cls = new wcfProxycall.ServiceReference1.MyServiceClient();
cls.Open();
Response.Write( cls.addData(5, 4));
cls.Close();
}



Step 3: Now save the project and run it. If every thing goes fine then the output will be like this.



Hope this article may helped you to understand and build a simple addition programme in WCF.

Thanks.

Tuesday, April 21, 2009

Working with instance and static constructor in C# 2.0

Abstract

In this article, i am gonna tell u about the static and non-static constructor. After going through this snippet, reader gets a clear cut understanding of the steps involved in object initialization (Both static and non-static).

Introduction

In C#, constructor is defined as a method which gets called whenever an object is created. A constructor may or may not have arguments without any return type. In C#, we also have static constructors. Static constructors are used to initialize Static variables. Let us understand how and when these constructors get called.

Code Snippet

The code below explains when an instance constructor gets called in class.

using System;
public class A
{
//Constructor of Class A
public A()
{
Console.WriteLine("Constructor of Class A");
}
}

public class B: A
{
//Constructor of Class B
public B()
{
Console.WriteLine("Constructor of Class B");
}
}

public class C: B
{
//Constructor of Class C
public C()
{
Console.WriteLine("Constructor of Class C");
}
}

public class Client
{
static void Main(string[]args)
{
// Initializing the class C's constructor.
C c = new C();
Console.Read();
}
}

Figure 1

In the above screen,Constructor of Class A gets called first, constructor of
Class B gets called and constructor of Class C then. Class A is the base
class and hence we understand that constructor of A gets called first.
This behavior of the code is expected.

The code below explains when an instance n static constructor gets called in class.


using System;
public class A
{
//Static Constructor of Class A
static A()
{
Console.WriteLine("Static Constructor of Class A");
}

//Constructor of Class A
public A()
{
Console.WriteLine("Constructor of Class A");
}
}

public class B: A
{
//Static Constructor of Class B
static B()
{
Console.WriteLine("Static Constructor of Class B");
}

//Constructor of Class B
public B()
{
Console.WriteLine("Constructor of Class B");
}
}

public class C: B
{
//Static Constructor of Class A
static C()
{
Console.WriteLine("Static Constructor of Class C");
}

//Constructor of Class C
public C()
{
Console.WriteLine("Constructor of Class C");
}
}

public class Client
{
static void Main(string[]args)
{
// Initializing the class C's constructor.
C c = new C();
Console.Read();
}
}

Figure 2

Surprised witht this output. This is the obevious behaviour of this. When the .NET runtime executes the statement "new C()" it understands that it has to create an object of C. Then it calls the static constructor of class C. It then calls the static constructor of the class B and then A. The instance constructor of the class A, B and C are then called.

Conclusion

Whenever an object gets initialized .NET runtime executes the object in 2 passes. In the first pass it initializes all the static variables in the upward hierarchy by calling the static constructors. In the second pass it executes all the instance constructors in the downward hierarchy.

Wednesday, February 4, 2009

Do Children Not Have Any Right?


A few days ago 9-year-old Komal was brutally hit by policemen. They had hit her for allegedly stealing 280 rupees. Is this humanity of the so-called police?

A day after the top cop of Uttar Pradesh camped at her home all day, trying to do damage control. After all this only two officers had been suspended and what about the others.

The sub inspector who actually hit her was sent to jail. His senior police was let off on bail. I am not able to understand that, what the morality of the so called policemen are having . The government has appointed them to protect, not to threat or beat. The child is of only nine years, what she knows about the stealing. If she accepted that she took the money, even though they don't have any right to beat the child like hell. This is ferociousness.

This inhuman treatment should be protested by all people and NGOs. The Child organization should protest against this inhumanity. I profoundly hurt with this incident. The National Commission for Protection of Child Rights (NCPCR) wants to use this case as an example of how not to deal with children.

It's not that laws are not there to protect the children. Among others, India is a signatory of the UN Convention on Protection of Child Rights. The policemen need to be aware that children have rights too. Just saying sorry isn't enough. An FIR should be filed against these policemen.


Tuesday, February 3, 2009

Mangalore Incident


The shameful act done by some unsocial element. The attack on young women in a pub in Mangalore is nothing but the work of frustrated elements in our society.

Exactly a week after the incident - all the 27 arrested in the Mangalore molestation case - walk free. A local court in Mangalore on Saturday (January 31) granted bail to all the 27 Sri Rama Sene activists arrested in connection with the Mangalore pub attack.

The so-called moral brigade is just a charade to vent their frustrations in life. If they think they are "protectors" of Indian culture, they should do what ever they feel using legal means.

They can approach the courts to have all bars and pubs closed because they are also not a part of Indian culture. If they want to preserve Indian culture, they should be wearing only dhoti-kurtas and not shirts and trousers as they are not part of our culture.

This is not done. A handful of people take us for a ride and the rest of he public stand and watch the show. Shame on us!

The police should round up these people and should have the same group of women beat these men in full public view. If this happens a couple of times, I am sure nobody will dare to repeat their shameful act.

Sunday, February 1, 2009

First Indian woman Grand Slam winner


The feeling of creating history has started to sink in and Sania Mirza, who today became the first Indian woman Grand Slam winner, says the way the new season has started, Indian tennis is definitely in for some good time ahead. The 22-year-old Hyderabadi ace said she is not only "enjoying" the moment of but also hoping that this feat of her, together with Mahesh Bhupathi, will further provide fillip to the game in the country.

"It took a few minutes to believe (that I have won my first Grand Slam title). It's great to be a Grand Slam winner.

I am at the airport and enjoying the moment. It's a dream come true," Sania told PTI from Melbourne as she prepared to flying home back.

Sania reckoned the last few weeks have been amazing for Indian tennis and it all started with the rise of Somdev Devavrman who reached final of Chennai Open. "Of course it was a great start with Somdev, then Yuki won yesterday and we won today.

It's great to beginning to the year and I hope Indian tennis gets more fillip from these feats," she said. Sania looked much more impressive this year and she combined excellently with Bhupathi throughout the tournament.

Diary of Barack Obama's desi roommate

The ongoing search for all photos and documents from President diary.jpg Obama’s past has turned up a diary that his desi roommate kept in the early 1980s. Some of the entries are quite revealing:

Aug. 28, 1981: Barack and I went searching for furniture today. We found a couch that someone had dumped on the street. It doesn’t look too bad, once we turned the cushions over. It doesn’t smell bad either, once Barack sprayed it with his Brut.

Sept. 14, 1981: Barack and I have been eating pizza, macaroni and cheese, and Ramen noodles for dinner. But today, I decided to make chicken karahi for a change. Barack tasted it and said, “Mmmm … This is a good change. Did I tell you how much I believe in change?”

Oct. 2, 1981: I tried to get Barack to give up cigarettes today. I said to him, “Why smoke cigarettes when you can smoke pot?” But it didn’t work. Poor guy. He really needs some help.

Nov. 13, 1981: Barack is a little too square. I’m trying to get him to be more stylish, more cool. Yesterday, I took him to see Sholay at a friend’s house, hoping that Amitabh Bachchan’s style would rub off on him. And today, Barack is walking around wearing a wide-collared shirt and saying, “Tera naam kya hai, Basanti?”

Nov. 20, 1981: Barack is such a dreamer. He talks about being leader of America one day. I told him that he needs to shoot for something more realistic, such as leader of the church choir. I mean, the day a black man becomes leader of America is the day I need to give up weed.

Dec. 11, 1981: I spent the entire morning teaching Barack how to pronounce Pakistan. He kept saying “Pack-he-stan.” He finally got it right though. In a few days, we’ll try it again and this time without the rubber band on his tongue.

Jan. 14, 1981: I wish I was as smart as Barack. His brain is like a sponge. Mine is like a stone. When we go to nightclubs, he doesn’t have to write any phone numbers down. Neither do I, but that’s another story.

March 3, 1982: Barack is concerned about all the homeless people in the city. He says he wants to show them how they can help themselves. “It’s a good idea,” I told him. “Just do it on the street, not in our apartment. I don’t want them helping themselves here.”

April 22, 1982: Barack and I are really into the party scene. I’m always ready to go to a party and he’s always recruiting for one.

May 8, 1982: Barack dragged me along to the basketball court this evening. Some other guys were there too. Barack and another guy picked teams. I was the worst player there, but Barack picked me first. On the way home, he said, “Winning isn’t everything. Besides, none of those other guys knows how to make chicken karahi.”

My First Blog.


Hello Every One....

I thought a lot about, what should i write in my first blog. I could not find any thing in my mind, as i had been thinking form past 2-3 hours. I have searched on Google, what should i write in my first blog, but all of was a vain attempt.

Frankly speaking, i was not interested in writing blogs. I always scared of writing. Once i had tried to write diary( after 10+2 ) but after writing 2 to 3 pages, i got fed up of writing, so i quit that.

Even some days ago when the blog site had started and every one was writing their blog, that time i was thinking what is all this fuss!! But now i realized that it is a good way to express your thought, experience, knowledge and not least but most important, happenings around us or in the world.

I am very inspired of this quotes, this really speaks when you read. you will also think of what it speaks.

"Your profession is not what brings home your paycheck. Your profession is what you were put on earth to do. With such passion and such intensity that it becomes spiritual in calling." By-Leo Buscaglia

Dr. Felice Leonardo Buscaglia Ph.D. (31 March 1924 of Italian descent – 11 June 1998) was a professor in the Department of Special Education at the University of Southern California. He was a graduate of Theodore Roosevelt High School (Los Angeles).

At last but not least, i will thank all of you who have given their valuable time to read this blog. In future, i will be posting important stuffs and happening news around the us.

Thank You.

Regards,
Divyalok Suman.