Venn diagram of developer types

Hey readers, It has been so long since we had a chat [Even one way :-)]. Have been busy with lot of things. But as I have been saying in past, The more busy I’m, the more I got for you to read.  So, le’s come to the point.
It has been roughly a decade since I am privileged to be in Software Development field. During that period, have played different roles. Now, When I look back, I try to analyze lot of things and I came up with my understanding about type of developers. You might ask why I need to know type of developers. Here are my views why:

  1. Hiring : When you are hiring new developers, you need to understand which type of developer is this and which type of developer you are looking for or your team needs right now [I have been part of roughly >50 interviews till this time, and hiring is also one of the data source for this blog post]
  2. Coaching and mentoring : If you know various types of developers and based on that if you identify someone is of some type and he/she should work on X/Y/Z to be of some else type etc.
  3. Forming team: When you start a new project, and you are one of the team selector, Then it will be good to know and make a balanced team.
  4. Self improvement: After reading this post, and If you agree what I am going to say then this post might help you to identify your type and work towards improving other aspects and be THAT BEST DEVELOPER Which World is searching for!

Enough reasons to convince you to read this further? 🙂
I thought a bit and then came a Eureka moment — Where an idea came, Why don’t we use Venn diagram to explain this! And I’m excited to share output with you:
 
venn_diagram_for_developers
 
Let me explain these types in detail:
Mainly they are based on their thinking style

  1. Technical : They are super technical. They know each technology as soon as they are available. They would like to get their hands on it and would love to implement it in their current/future project. There are quite a few who will try to fit new technology without even fully understanding it. But they will have solution for all technical problems. And each project must have at least one of  them. They make good Technical Architect or Technical role.
  2. Business : This type of devs will understand business very well. They speak client’s language and that’s why most of the time client loves to work with them.
  3. Analytical : This person thinks all things from analytical point of view. (s)he will come up with the easiest and best solution which neither technical/analytical person can think of. They will not be super strong in technical. But If you pair this dev with Technical team member they rock
  4. Technical-Business-Analytical: And you know that sweet spot, when one person can think from all angles. YES, they do exist. But sadly they are very few and again this type of thinking takes sometime. Because when you are out of college, initially you think to solve everything using technology. Because that’s what you have been taught. But gradually, If you mentor someone closely they can come in this type in a longer run. Usually, This type of folks should be leading a team.

So, what makes a best team? It depends on lot of factors, e.g. Project complexity, Resource availability etc. But If you want to make super complex project successful. I would recommend, Combination of these types will rock your project. And that’s what I look for when I have to form a team — Sharing my secret with a wish that you will share with others!
Happy Team Building! 🙂

Winning Teams Basics

As Cricket world cup has completed and Australian team won it again (Congratulations to them!), and apart from few people in India. Cricket is religion for most of us. You too – Correct?

“Winning is habit. Unfortunately, so is losing.” – Vince Lombardi

I know we lost in Semis against Australia – But as Dhoni rightly said “it’s a sport and only one team can win”. And let’s be honest guys and girls too – When Indian team went for World cup all of us, expected that these team won’t reach so far. And here’s when human expectations comes in to the picture,  When we started winning, Our expectation raised. And we wanted team to win world cup. But my personal view is that day Australia played good cricket. And we failed to do so. But I’m sure team will take a learning lesson from this and they do better next time! Sorry for taking conversation off track. But it shows, I’m same like you! When it comes to Cricket – We become experts. I personally believe everyone should follow/play at least one sport. It teaches you lot of lessons, which helps you in real life as well! Best lesson is “Match is never end till last ball” – Follow this rule in real life. At last moment (Yes, last moment) there is a chance that things becomes favorable to you. You just need to stay on the pitch! So, whatever the tough situation you are going through. Just be there on pitch! You might be thinking – Why there are few teams, who always keeps winning? And the other one always keeps losing? (In Cricket and in real life too). And I was thinking to apply this logic, in software industry as well. Why few teams always deliver software project successfully and smoothly. And other ones struggle to do so. As per my view there are two types of teams: Type1 : You can identify them using following characteristics:

  1. People love to be at office
  2. Whatever project they work – It gets successfully delivered
  3. No weekend work (If Project needs them, they will be happy to be available)
  4. Everyone goes at home happily and enjoys his/her personal life
  5. Passionate
  6. Enjoying each others in win
  7. They are always happy and cheerful
  8. Not Stressed

Typ2 : You can identify them using following characteristics:

  1. People look forward for way to not be at office
  2. Whatever project they work – It never gets successfully delivered
  3. Always in office during weekend (Few people like to be in the office during weekend for some research or something. But I don’t count them here. They belong to first team. I would consider people who don’t like to be in the office during weekend. But have to be, as SOMEONE has ASKED them to do so)
  4. Not so passionate – Doing something for just sake of doing
  5. No team bonding
  6. Always frustrated
  7. Always stressed

Sounds similar? If you belong to Type1, then you are the luckiest person in this world. But if you don’t know how it works? And would like to understand few reasons behind it. Then this blog post is for you. If you are in Type2, then I’ve an empathy for you. And would suggest that you work out on following points. They will surely help. And if you don’t have that level of control or someone is stopping you from doing so. Would suggest – Get off the bus! http://www.motivation.careers360.com/Hope-and-Motivation/If-you-are-not-enjoying-the-ride-Then-get-off-the-Bus So, let’s see what special Type1 team does to be there:

Disclaimer : This is based on my learnings. I am not expert on this subject. But few basics which I learnt through my journey and have noted it down. Which I am sharing with you. So, if you think something might not work for you. Feel free to ignore it

  1. Leader: I believe team and team’s leaders makes most difference. Because if leader is not secure. Then he/she won’t let team grow. And then the culture becomes worst and worst. But if leader is confident, technically sound, and smart and get things done person. Then team also follows him/her. So, while making someone a leader, please think twice. “People don’t leave company they leave bad leader/manager” And if you are a leader, then I request you to give your best. Because I believe – The responsibility what our Teachers had at School/College level, Parents had at child level, the same level of responsibility leaders have at professional level. “Good leaders create leaders, and others create followers” https://www.ted.com/talks/simon_sinek_why_good_leaders_make_you_feel_safe
  2. People : If Leader is important, Then People working in the team are also equally important. Because people get things done and NOT Process. It makes me amazed that lot of companies focus on setting up good process. But I believe have good people, the process will be automatically good. Their Hiring Process is very strict. They can identify the talent, and know how to groom them! “Only good leader’s eyes can spot, good candidates/leaders”. While Hiring they keep person’s attitude first and technical skills second. Because it’s easy to impart Technical skills than attitude!
  3. Culture  : Company’s culture also makes difference. Always hire smart people, and let them do what they think is right. Company should just act as a facilitator. See Google’s work culture!
  4. Timesheets : I agree that time-sheets are good way to track and manage your time. Because based on that we bill to clients. But at times, people just work to fill in their 40 hours. And in this process they lose their creativity and helping nature.
  5. Team bonding : They not only enjoy and spend time with each other in office. But out of office as well. They do spend lot of time together! Type2 teams works more as individuals
  6. Communication and Transparency : Communications are very clear in these type of teams. Things are Green/Red.  Anyone can speak out. All things are 100% Transparent. Feedback system is also good!
  7. Training : They have very good training process. So, when someone joins the team. He/she knows what/how these team works. Before he/she gets bombarded with so-called strict deadlines. And lack of training makes it stricter!
  8. Balanced between experience and fresher : They have good balance between fresher and experience. Because both combination is required. But as good cook knows, the best ingredient to make good food. Same logic applies here as well. Experience people brings the lot of knowledge and best practices in to the team, at the same time. Freshers brings the lot of new perspective in the team. And while working together, they share those things with each others. And at the end of the day – Everyone wins!
  9. Clear expectations : As I mentioned in #1, Leader is very important. Because Good leaders are always good in communicating expectations clearly. I believe most of the time Type2 are frustrated because of this reason. Leader and Team members are never in sync with their expectations. I think, as a leader if you let people know what is right and what is wrong. And what you expect from them. Then they make sure they do it!
  10. Allowed to make mistakes : Team is allowed to make mistakes. But yes, they are not allowed to repeat them. But as Type1 team learns from mistakes. They rarely repeat any mistake. How leaders should manage their team success and failure- Dr. A. P. J. Abdul Kalam
  11. Learning from mistakes :  As Type2 teams are always busy. They just keep running because they are busy. But they never take a step back, and think what is keeping them busy? What mistakes they are doing? How they can learn from them? And Type1 team always learn from their mistakes and shares it with others. So, they don’t repeat it. And that’s how they get things done faster.
  12. Ready to help : They are always ready to help each others, and ready to go out-of-the-way for team
  13. Competition: They don’t compete with each other, they complement each other. If they have competition. That will be healthy completion. Who commits more backlogs/tickets in this release? 🙂 And Competition stuff happens with most of us. Because since school level. We’ve been asked to be first. In Public Transportation (Bus/Train) as well, we always try to be first! But those concepts doesn’t fit while working in a Team
  14. Helps others in down time : The time is not going to be same for anyone. Sometime X is doing well, at that time, Y is struggling. And when Y is doing well. X is struggling. In all situations they help each other during someone Else’s down time
  15. Links : You may find few more points from my earlier leadership posts:
    1. https://kiranpatils.wordpress.com/tag/leadership/

Remember TEAM == Together each achieves more! Sounds good? Have I missed something? Would be happy to incorporate your views.

It is better to lead from behind and to put others in front, especially when you celebrate victory when nice things occur. You take the front line when there is danger. Then people will appreciate your leadership – Nelson Mandela

You are starting your career in IT Industry? Here are my learnings for you!

Hello Folks, Sorry I am facing challenges in keeping this blog updated. I wish can get more than 24 hours :-). I know it’s not possible. But will keep posting on this blog. Because from this blog only I got to learn lot of things. While sharing things with you. Quantity will be less compared to earlier. But quality will be same/more than earlier for sure! Because I believe in never compromising with quality!
Start-CareerMonth of May-July is the month, when every company starts on-boarding university/college pass-outs in their company. So, lot of new people start working professionally in IT Industry. So, if you are one of them — I welcome you to an IT Industry!
Now, when you start working in this Industry, You feel lot excited. But more confused as well. Because what you learnt in college, and what people do in industry is totally different, until and unless you are from Good College/University. Who encourage to have working professional as a guest lecturer.
When you start working for any company. And you got a nice mentor — Who can clear all your doubts, Help you understand what is right, what is wrong, Guide you in getting comfortable with all the tools and terminologies, Who is always there for you. But if you get one then you are lucky!
As per my view good mentor should have :

  1. Lot of patience
  2. And passion about the profession what they are in

When I started my career, I’ve been lucky at times, by having great mentors, who taught me What To Do, And How To DO. And have been super lucky to have some not so good mentors, from whom I Learnt — What Not To Do, How Not To Do, And How Not To Behave. And my big thanks to second one. Because I learnt a lot from them then the first one!
Since few year, I’ve been lucky enough to mentor — super talented and smart people. And I’ve thoroughly enjoyed them shining. Because they were Diamonds. I just got a chance to polish them and make them shine! You are also a Mentor? Then buddy you got a big responsibility on your shoulders. Because I believe Mentor has to play a role, Which Parents played during nurturing, Teacher played during School/College. So, when your mentee comes to you with small questions — Don’t lose patience, answer them politely.  Quench their thirst. And while doing so, you will learn a lot of new things — It’s a two-way process. I learnt a lot from my students. Basically if we just look around, We’ve a lot to learn from each others! — John West Sitecore CTO nicely said on Mentoring:
When a new developer joins your team or project, be friendly and let them know you are available for a two-way learning process. If an inexperienced Sitecore developer has a newbie question, instead of ignoring it or feeling frustrated, show that you care, take pride in trying to educate them on the topic, and try to provide pointers to the next few areas they could research. This works best when we all approach it the same way. Consider everyone with whom you interact to be both your mentor and your mentee. When I used to teach CMS training, I was surprised constantly by how much I learned from my students. In fact, I think each of us has something to learn from every other individual.
Source : http://www.sitecore.net/belgie/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2013/06/My-Sitecore-Story-Mentoring.aspx
You may also like these:

While mentoring them, What I used to do, used to go back in my career and check, What Good things I learnt? — So, I can pass on to them. What Bad Things I learnt? — So, I can’t pass same to them. What I haven’t got? — So, I can get it for them.
So, each year – I meet a lot of young people joining our industry, and I make sure I share my learnings with them and help them shine! At one evening I thought, At each year — How many young folks — I will meet — 4,5,6 That’s it! — So, Why don’t I share my learning via my blog. So, who are starting your career, can focus on it. And if someone is new in mentoring and one of my learning can help them then I feel paid off!

Disclaimer : This is based on my learnings. I am not expert on this subject. But few basics which I learnt through my journey and have noted it down. Which I am sharing with you. So, if you think something might not work for you. Feel free to ignore it

Let’s go!

  1. Learn : When you start your career, Keep focusing on Learning and NOT Earning! [As Allan Border Said to Harsha Bhogle — Take care of the runs – the dollars will take care of themselves.] An Advice I follow and give — For Initial years — Just learn as much as you can! Spend as much as time you can to learn the things, understand things. Ask questions. Do R&D
  2. Mentor : If possible find a Good Mentor and follow him/her
  3. Don’t Say No : If some new task is coming up to you. Don’t say NO — If you don’t know, tell them I will need sometime. But i will do it.  Be a Go-Getter [Quotable Quote : Richard Branson — ‘If somebody offers you an amazing opportunity but you are not sure you can do it, say yes – then learn how to do it later!’] But Yes, don’t get overburdened and over commit.
  4. Give Respect : Give respect to your seniors, subordinates and even office peons!. Be a team player! And they will love to work with you!
  5. Master your Skills : Whatever skills you are in for example .NET Developer/Java Developer/QA — Master it! And to be different from crowd — Get your self certified — I did most of my Microsoft Certifications during initial years — It not only added value. But also clarified lot of my basic thoughts about programming, I came to know lot of new API — Which made my work easier, and faster. [Yes, please read Microsoft certification books before giving exam, and DON’T GIVE EXAMS BY JUST READING DUMPS]
  6. Focus on your Coding Standards : They will consider that you care for your code!
  7. Read Read Read : In the era of internet as well, disconnecting from live world and reading a book for Minimum 30 minutes Enriches you. First read as many technical books you can may it be – OOPS, Design Patterns, .NET Frameworks, 97 Things every programmer should know or talk to your colleagues and find out which book they like more. Apart from that read the books you like Fiction/Non-Fiction/Self Help — This will keep you motivated! This is so long back I wrote on World Book Day : Did you know that, today is World Book day?!Books can be really your best friend! – Who gives a lot, and asks nothing in return!, which expands your vision about life! Who helps you to stand like a rock in difficult situation! Who makes you laugh, who makes you cry!If you read technical books – your technical knowledge will get increased and if you read other books (Biography, self-help, novel etc.) – your life’s knowledge will get increased – at last you will feel enriched for sure!It’s interesting, when I talk to people and ask about reading books they say – “Where is time to read the books?” – It’s same as driving a fast running car. But you don’t have a time to fuel it!:-)In this fast pacing era, promise yourself to daily read for min. 30 minutes, it will surely change your life – it worked for me, and I’m sure it will work for you as well!So, grab a copy of a book which you was “planing” to read from a long time and start reading it “today”!Happy World Book day!
  8. Document your learnings : In your initial days you will learn new things at every footstep. Our teacher taught us, Whatever new thing you learn document it. So, your knowledge gets organized in a proper manner, it gets stored in your permanent sector. And if you can write  your blog then nothing great like that! The one blog you are reading is the best example of it! It improved my writing Skills and when people comment on blog — “You saved my day, God Bless you!” — That’s the best feeling you can ever have — Good Reads : http://pluralsight.com/training/Courses/TableOfContents/get-involved and http://www.hanselman.com/blog/YourWordsAreWasted.aspx
  9. Communication Skills : Sharpen your written and verbal skills. Because along with compilers you’ve to work with HUMANS. And when you get stuck with something. You’ve to explain it nicely to your senior, colleague, subordinate, Or In Global era to someone else sitting in U.S/U.K Or in Forum or To Support guys. And before you start working you’ve to understand requirements as well. If you can’t deliver something as committed, please communicate before hand.
  10. Develop Tools —  When you learn something new in Technology. Think of how you can use it in your day-to-day life. If not in your project then can you build a small tool for your personal use or professional use or for your company’s use? It will give two benefits — It will clarify your concepts thoroughly, and at the end of  the day, you will have a tool which simplifies someone’s task. See Tools i wrote for fun — PolyglotSkype, TimeZoneConverter or you can start your open source project on GitHub!
  11. Stand in tough time :When something is not working and the whole team is in tough time. Go and stand their. You might not be able to help. But see what you can do. At times fresh perspective might show a way to solve a problem! And you learn more in tough situations than day-to-day situations!
  12. Share Knowledge — Learnt something new? Share with someone else as soon as you can! Don’t feel insecure while sharing the knowledge. Good Read : http://prakashiyer.com/a-tale-of-two-seas/
  13. Track your progress : Periodically, take a halt and check how you are moving? What good things you did? What bad things you did? If needed talk to your Mentor/Senior and ask for an HONEST Feedback — Don’t wait for Annual Appraisal. BTW, I’m big fan of writing Journals. Give it a try, It will give you astonishing results!
  14. Usergroup meetings : If possible go for user group meeting
  15. Focus Focus Focus : Be focused, In this era of Social Media, you have no idea, how much of your time this social media mediums can eat. I’m not against in being touch with friends and family — That matters a lot! But while you are working — You are working! And When you are playing, You are playing — Then don’t work! I believe in “Work Hard, Play Hard” And you got finite number of key strokes in your life, please don’t get it wasted — http://www.hanselman.com/blog/YourWordsAreWasted.aspx Check your keys left : http://keysleft.com/ [I have only 156,038,394 keystrokes left before I die.] and “Choose a job you love, and you will never have to work a day in your life.” – Confucius
  16. Quality : Never Never Never compromise on quality. If you’ve to delay your software delivery by a day or deliver one feature less — In place of a quality — It’s a good deal! If you’ve to burn yourself for a quality — Just do it! Steve Jobs is the prime example of quality lovers and he nicely said “When you’re a carpenter making a beautiful chest of drawers, you’re not going to use a piece of plywood on the back, even though it faces the wall and nobody will ever see it. You’ll know it’s there, so you’re going to use a beautiful piece of wood on the back. For you to sleep well at night, the aesthetic, the quality, has to be carried all the way through.” Good Read : http://blog.hubspot.com/marketing/steve-jobs-inspirational-quotes-im-slideshare
  17. Be Efficient  : Complete your assigned tasks on time. Do a Time management. Say No where you can Say NO.
  18. Be Responsible : If you take more responsibility you will be assigned on more and important projects — and you will be important player of your team!
  19. Basics : And one advice, I always give — “Always Stick  to your Basics” In whatever things Technical/Non Technical — Because it matters! “Back to Basic, Stick to basics, because a basic always works!”

Have I missed something? Feel free to comment
I hope this pointers, help you to shine in your career! Always Remember — “No idea works, Unless you do!”

“Twenty years from now you will be more disappointed by the things that you didn’t do than by the ones you did do. So throw off the bowlines. Sail away from the safe harbor. Catch the trade winds in your sails. Explore. Dream. Discover.”

And If you need any help from my side, Just give me a shout!
Have a Happy and Nice Vacation! 🙂 [“When Passion becomes Profession, life Becomes Vacation!”]
Good Reads:
Driving Your Career : http://www.brianhprince.com/2010/04/14/driving-your-career-series-transcripts/

ASP.NET Website Performance Basics – Part 2

Challenge:

Recap : In last part of ASP.NET Website performance basics, Dax shared basic methodology of troubleshooting ASP.NET Website performance challenges!
Where he shared, what all things we need to do, and why we should do it (Remember W-W-H theory?). And just pointers of How to do it! And as Dax promised, that he will help us to understand how part more [We all know, how well Dax keeps his promises! :)] and here he is.
In this post [Would also name it “ASP.NET Basics”], we will look at following things (Which are very IMP. to diagnose performance issues):

  1. When you open any website from your browser, what all happens, behind the scenes? — Not related to ASP.NET just basics, how it reaches till your ASP.NET Application
  2. Now, we’ve reached to ASP.NET Application, after that we will look at — ASP.NET Application LifeCycle — All about — HttpApplication,HttpContext,HttpRuntime, HttpModules etc.
  3. Request Queuing
  4. Major Performance killers ( Hanging Requests, Session can slowdown your application — Thread Agility Issue, Exceptions and performance co-relation, MaxConnections, High GC, Contentions, App Pool Recycle, Memory leak)

Above topics sounds similar? Very Basic? (Back to Basics, Stick to basics. Because a basic always works!) But still unknown? (During our interview sessions, we ask these questions to most of our candidate, And so less can answer it)Don’t worry, we will learn it, So, as Dax and his team!
Here we go!

Solution:

When you open any website from your browser, what all happens, behind the scenes?

You might know this question or learnt it during your college days. And If you are pretty much confident you know this you can skip it. But Dax recommends that even though you know it. It would be a good idea to brush up this stuff.
Because while working on performance stuff, you need to know about everything starting from Client’s Browser, DNS, Firewall, Switch — You no need to be expert in this subject. But when you troubleshoot it, You should know all these players very well.
My favorite — one is from MCTS 70-528 exam book – Chapter1-Lesson1 – Understanding the PlayersMajor-Players
Another good articles:
http://www.codeproject.com/Articles/121096/Web-Server-and-ASP-NET-Application-Life-Cycle-in-D
http://www.codeproject.com/Articles/73728/ASP-NET-Application-and-Page-Life-Cycle

Good to remember about M-H-P-M

http://www.codeproject.com/Articles/87316/A-walkthrough-to-Application-State
Thanks a lot to author of above articles. It clarifies everything. So, now you know what all happens — from browser till server — a request goes through a journey and then gets served!
Here you must’ve seen about HttpApplication object, this guy is very critical while serving your requests.  HttpApplication consists of HttpModules.
index
 
http://blog.andreloker.de/post/2008/05/HttpApplication-instances.aspx
HttpApplication Gotchas:

  1. ASP.NET may instantiate many instances of HttpApplication as required (. In fact, it will create an instance of the class for each request that is handled in parallel on the server.
  2. “ASP.NET maintains a pool of HttpApplication instances over the course of a Web application’s lifetime. ASP.NET automatically assigns one of these instances to process each incoming HTTP request that is received by the application. The particular HttpApplication instance assigned is responsible for managing the entire lifetime of the request and is reused only after the request has been completed. This means that user code within the HttpApplication does not need to be reentrant.”
  3. You can observe asp.net pipeline instance count in the performance counters to see how many instances of your HttpApplication class are pooled at the moment.
  4. In Integrated Application mode — HttpApplication will called once during application initialization and another during the first request
  5. When ASP.NET Creates Instance of the HttpApplication class that represents your application, instance of any odules that have been registered are created. When a Module is created, its Init method is called and the module initializes itself. — and the custom module will run for all resource handler, even though resource handler is not an ASP.NET handler
  6. If you see More number of requests [You can check it via IIS log or performance counter] and Heavy HttpApplication Instances is Normal, Because it means that current HttpApplication Pool was not enough and ASP.NET need to spawn worker processes.
  7. But if you see less number of requests, and still see heavy HttpApplication instances then it is abnormal. We need to find out slow pages/handlers etc.
  8. ASP.NET run-time keeps two pools of HttpApplication objects. First is a special pool with HttpApplication objects used for application level events (such as Application_Start, Application_End), Second pool contains instances used in requests to serve all other types of events
  9. Try this out — http://lowleveldesign.wordpress.com/2011/07/20/global-asax-in-asp-net/
  10. HttpApplication Events

HttpApplication-Events
Other good reads:

Huh! Load of things, correct? Useful? Dax says these information is really useful and it will clarify your understanding more on ASP.NET internals!

Request Queuing

It is really good to know about Request Queuing, lot of us already know about Request Queuing — Simple, a Request is queuing. Yes, my dear friend you are right. But there are different level of Queuing happens. And untill and unless you know your request is queued at which level, it won’t be easy to fix it!
Great post! — http://blog.leansentry.com/2013/07/all-about-iis-asp-net-request-queues/
Basically, Request Queuing can happen at mainly 4 levels:

  1. HTTP.SYS: Application pool queue
  2. IIS worker process: completion port
  3. ASP.NET: CLR threadpool queue
  4. ASP.NET: Integrated mode global queue
  5. [OR]ASP.NET: Classic mode application queue

Request_Timeline2 Req-Q
Source — http://fullsocrates.wordpress.com/2013/02/28/asp-net-threadstuning-thread-parameters-12-2/
To diagnose, your level of Queuing. Best thing is performance counters [Dax, is going to share more on performance counters in his upcoming posts] and once found you can use tools like FRT, Dump analysis etc. to find a main bottleneck [Yes, Yes — Dax will post on these topics in future for you!]

Major Performance Killers

  1. Application Pool Recycle/Crash — If your application pool is crashing is or recycling [How Can I check that? You can check EventLog OR if your application got log do log entry [Just a note : Application_End will not get called, when your application crashed unexpectedly a.k.a. Crash] — see — http://weblogs.asp.net/scottgu/archive/2005/12/14/433194.aspx] periodically than it’s not good for your application’s health. Because when application pool gets recycled everything in memory [Session/Cache/Static/Application objects] gets lost, and your application need to server everything from Database and rebuild cache. You can solve this issue by checking EventLog and Configuring+Analyzing Crash Dump.http://kiranpatils.wordpress.com/2012/06/20/is-it-necessary-to-recycle-worker-process-periodically/ and http://kiranpatils.wordpress.com/2010/05/25/goo-to-know-on-asp-net-application-restarts/
  2. Hanging Requests — Your users are complaining that the site is loading slowly. Requests to your application are hanging. With so many possible causes of request hangs, its difficult to know where to even start. — http://mvolo.com/troubleshoot-iis-hanging-requests/
  3. Exceptions, handle them gracefully — Exceptions can slowdown your application. Because when your application throws an exception — It Creates objects — CLR needs to do object allocation — And after that GC for those allocation! [Analyze your application logs to see exceptions, and handle them gracefully] — http://blogs.msdn.com/b/tess/archive/2005/11/30/498297.aspx
  4. %Time in GC — When this time is high, your requests will get paused for a while and your end users will see slow response time during this time. If it is >=10% then you need to dig in to this issue.  Also, check for Memory Leak — http://kiranpatils.wordpress.com/2012/06/05/basics-of-memory-leak/
  5. Contentions — If your CPU is not being utilized and you still see low throughput, you may be suffering from high contention rate. Means your code has lock on shared resources, which is taking time to process, and due to this other requests are going in Queue. Simple concept in locking — “Acquire lock as late as possible, and release it as soon as possible” http://kiranpatils.wordpress.com/2013/01/13/thread-synchronization-basics/
  6. Session lock – Thread agility issue Disable session for the pages/handlers, where you don’t need them. https://github.com/angieslist/AL-Redis http://stackoverflow.com/questions/3629709/i-just-discovered-why-all-asp-net-websites-are-slow-and-i-am-trying-to-work-out
    http://stackoverflow.com/questions/8068925/redis-backed-asp-net-sessionstate-provider

Good to read resources:

  1. http://msdn.microsoft.com/en-us/library/ff647787.aspx
  2. Most recommended — https://www.leansentry.com/try#course
  3. http://blogs.msdn.com/b/mcsuksoldev/archive/2011/01/19/common-performance-issues-on-asp-net-web-sites.aspx
  4. http://www.codeproject.com/Articles/23306/10-ASP-NET-Performance-and-Scalability-Secrets
  5. http://blog.leansentry.com/2013/07/the-server-logs-you-need-to-know-to-fix-any-iis-aspnet-error/
  6. http://mvolo.com/fix-the-3-high-cpu-performance-problems-for-iis-aspnet-apps/

Sorry for such a long post. But It’s good to clarify basics. Because once it is clear, you can fix any issue!
These are the common performance killers, In upcoming posts, we will see how to diagnose them! Till than Happy Performance Tunning! 🙂
 

Leading is like parenting!

Thanks a lot for appreciating my first article on non-technical subject! (You haven’t had a read at it? Come on, lot of people liked it, and I hope you too! — Leadership basics!)
Your motivation has inspired me to write another blog post on same topic, leadership!
Leading is like parenting!, yes you heard right! Leading is like parenting! — This is what I’ve observed and analyzed, good leaders are like good parents! Not convinced correct? I know you are an engineer, to who E=MC2 also needs to be proved! 🙂 Let me try to prove it!
Below are few of the characteristics of good leader and good parent: (Just a note : Let me repeat, it stands true with good parent/leader. If you apply negation and read it again everything will be true in other way!)

Characteristic

Leader

Parent

Takes care They always take care of their team members, day in and day out they keep thinking about team! Do you agree that parents do the same? Parent always think of their Kids and they take best care of them, and if they need to suffer a bit for doing so, they will do it? So, as great leaders!
Future They always think about their team’s future! What’s good for their Kid!
Appreciates They appreciate in public If they have identified any quality of their kids, they will appreciate it In public and lets everyone know!
Criticizes If something is not right, let team member know, right now. Before it gets tough to manage! Can easily let you know, what wrong you are doing!
Laugh with you and shout on you! They laugh with you, But if he/she feels you are spoiled down, just give a shout in private! And you will never feel bad on their shout. Because you know they are saying for your goodness only! They always do this for our great future!
Holds your finger During your initial days, will hold your fingers and help you to understand everything! Do you remember who taught you how to walk? As far as I know, still this point of time there is no any APP in Android/App market for doing this! 🙂
Steps back When you are ready to fly, you won’t come to know that he has taken a step back and watching you from a distance, that how you are performing! Riding a bicycle, he/she will be with you still some point of time, and still the time you realize he/she is not there, you might have learnt how to ride a bicycle!
Protective With them you feel safe, they protect you from outsiders! You always feel secure with them!
Let you fail Good leaders, always protect their team. But at times, they let you get failed! Do you know why? Because If you haven’t learnt how to deal with failure, other things are in vain. Also, failure is a lousy teacher! If success teaches you 1 lesson, failure will teach you 100! – I firmly believe that “Failure is the key to success” They know, that If you can’t manage handle of a bicycle you will fall down. So, what? This is beginning and then only you will learn to wake up and say again! I will do it this time!
When you are down, they will make you up! Okay you failed, you are down! Feeling bad? Just turnaround, good leader will be standing next to you to motivate you and help you how to get out of it! Whatever worst happens with you, they are always by your side! Because they know you are right! – And trust me with their support you can overcome any situation!
Clear expectations They Communicate expectations to you and vice-versa! If you get distinction, will get you this?
Trust you Whatever happens they trust you! Always have a full trust on you!
Let you enjoy! Let you enjoy, with task and sometime without task as well! Let you enjoy your life without any interruptions!
Motivates to learn Always motivates you to learn, something new. Even though sometime you think I’ve learnt a lot. But he/she got some plans for your future! And you like it or not, will ask you to learn, learn and learn! And you see benefit of it in a longer run! Do you remember, your parents always telling you study, study, study? And you wanted to go for Cricket, TV and Games. But they made sure that you do your studies! And see today you are Engineer! 🙂

Convinced?
Happy Leading! 🙂

Leadership Basics

My dear readers, thanks for your support since ~5 years for appreciating my each and every blog by your invaluable reads, comments and suggestions — It always kept me motivated! (Just a note : It’s easy to start a blog. But it’s too tough to keep it updated! Most of you must be knowing this! and I would like to thank you for your support and motivation which kept me engaged on this blog! — Cordially, thank you!)
Since starting of my blog, I was sharing Technical stuff with you, and I’m sure you must have enjoyed it! Now, going to write this first blog post, which is not on technical stuff. But on leadership stuff i.e. Management stuff.
A question may come up in your mind, Now, this guy is moving to management and will not post anything related to code. Let me correct you, it will never ever happen for sure. Because coding is my passion and can’t live without it! But thought to share leadership learning with you for following reasons:

  1. As per my experience and observation, have worked with few nice leaders (and at the same time few bad as well!) and would like to thank both of them. Because knowing what not to do takes more time than knowing what to do! 🙂 and the other ones helped me to do so very quickly! In this blog post, will try to summarize the characteristics of a good leader [what I’ve seen], it’s solely based on my observations and reading whatever I had during my working experience as a leader since 2 years!
  2. Lot of you don’t know that, there is a leader within you! (This blog will help you to identify a leader within you!) Just check how many characteristics matches with you! (Don’t worry same happened with me as well, Because before two years, when I came to know that I’ve to lead a team — I was not ready for it! 🙂 )
  3. Or if you would like to be a good leader or already a leader and would like to improve your leadership skills then also this post will help you!
  4. If you are in a senior management and would like to identify a leader for your organization, this post may give you reference pointers!

Just a note : Let me repeat, I’m not a leadership guru. Whatever characteristics I’m going to share is just based on my analysis, observations,reading and working experience!
Let’s start! (Just a note : will write pointers or one liners only. In future, will expand few points from following list If you think you need detailed explanation on any pointer, feel free to drop it in a comment)

  1. Honest — still honesty is the best policy!
  2. Give his/her best in turbulent times — Whenever any crisis happens, they are the first one to solve them! They flourish in tough time! And spot them they are the great leaders!
  3. Transparent — No encapsulation please!
  4. Learn from mistakes — Someone did something wrong, don’t worry he/she is a human being. Just analyze the mistake and make sure you don’t repeat it and move on!
  5. Back your guys — Always back your guys, mostly in tough time!
  6. Cover them — Mainly from outsiders!
  7. Be open to them!
  8. Give honest feedback — Appreciate is public variable, and criticize is private! And do it on time! — If someone did a mistake/did something good don’t wait for his/her appraisal appreciate right now!
  9. Promise — Always fulfill your promise! Or take a note of it!
  10. Never bad mouth your team
  11. Take care of them — And they will take care of yours! Even their small needs e.g. Mouse, Keyboard desk etc. It matters a lot!
  12. Communicate — Whatever small things, each one of your team member should know everything. [Obviously, not the confidential one!]
  13. Inspire/Motivate them — “If your actions inspire others to dream more, learn more, do more and become more, you are a leader.” especially when they feel down!
  14. Expectations – Communicate your expectations to them and vice-versa!
  15. Always challenge them and sometime it’s good to keep them on their toes!
  16. Know them personally — Because people perform better when they get to work what they love to work!
  17. Speak with them — Every time you should not discuss about work, sometime just have a casual chat with them!
  18. Have a one to one meeting — Monthly?
  19. Share knowledge with them — Don’t feel insecure!
  20. Always give credit to them — and never accept any credit!
  21. Do their HR process rightly on time!
  22. Laugh with them
  23. Never order them — Rather than saying “You have to do it?” you should say “Can you please do it for me?”
  24. Be thankful to them – Because they make your life simple!
  25. If they are stuck somewhere — help them out!
  26. Roll your sleeves up — If needed, don’t be afraid to roll your sleeves up and start coding! This is the most IMP. characteristics!
  27. Fight for them — Fight for their rights!
  28. Always be cool and calm before them! — Never let them know that you are angry!
  29. Always be accessible to them — It’s frustrating for your team mates, if your are not accessible to them whenever they need you!
  30. Quick thinker — Think quick! and mainly act upon it!
  31. Act promptly — No one likes a leader, who just takes an issue and works on it for ages, we are living in 4G world! 🙂 Take a decision and act on it!
  32. People feels safe while working with you!
  33. People love to talk to you!
  34. Always positive!
  35. Take decision and back them no matter whatever happens!
  36. Always smiling face! 🙂
  37. Focused on solution — and not the problem or the problem source
  38. Never blames anyone!
  39. Expert in the field — I remember a nice line from Bill Gates — If you don’t know how to write a good code, then you can’t be a good leader. And trust me this characteristic will only gain you respect!
  40. Passionate
  41. Problem solver!
  42. Organized! Disciplined! [Still we are agile!]
  43. Best listening skills! — Always listen you!
  44. Caring!
  45. Always ready to discuss
  46. ______________________________

You can add your leanings here!
Helpful? As said earlier this my first management blog post, please ignore my mistakes and share your views about it! Will surely work on it!
And If you would like me to expand any characteristic from above list, just drop it in a comment. Will elaborate it for you!
Happy leading! 🙂

Why we use lookup tables in SQL

Challenge:


Few days back, we had a good discussion on lookup tables. Why we need them in our Database schema? Can’t we directly store simple status related text in parent table itself? why we add one extra table? why we need to do joins and fetch records out of it? If you also have such “whys” in your mind. Then this post is for you only!

Solution:

Basically, I was clear that we should use it? But the main thing is why? Did a quick search and found so many good links, but this stackoverflow discussion link [http://stackoverflow.com/questions/4824024/how-important-are-lookup-tables] sounds really perfect —  few points from discussion:

  • if you have “Open” and “Closed” repeated in data tables, that is a simple Normalisation error. If you change those values you may have to update millions of rows, which is very limited design. Such values are commonly normalised into a Reference or Lookup table. It also saves space. The value “Open”, “Closed” etc is no longer duplicated.
  • the second point is ease of change, if “Closed” were changed to “Expired”, again, one row needs to be changed, and that is reflected in the entire database; whereas in the unnormalised files, millions of rows need to be changed.
  • Enum is only for the Non-SQLS. In SQL the Enum is a Lookup table.
  • Since PKs are stable, particularly in Lookup tables, you can safely code:  WHERE status_id = ‘O’
  • And the users would choose the value from a drop-down that displayed “Open”, “Closed”, etc., not {0,1,2,4,5,6}, not {M, F, U}. Both in the apps, and in the report tool. Without a lookup table, you can’t do that.
  • The next point relates to the meaningfulness of the key. If the Key is meaningless to the user, fine, use an INT or TINYINT or whatever is suitable; number them incrementally; allow “gaps”. But if the Key is meaningful to the user, do not use a meaningless number, do use the meaningful key. “M” and “F” for Male and Female, etc.
  • Now some people will get in to tangents re the permanence of PKs. That is a separate point. Yes, of course, always use a stable value for a PK. “M” and “F” are unlikely to change; if you have used {0,1,2,4,5,6}, well don’t change it, why would you want to. Those values were supposed to be meaningless, only meaningful Key need to be changed.

And the final one, I liked most and modified a bit:

  • I always preferred the lookup table as opposed to constants because why duplicate a varchar(20) in every row when you can use a 1 byte tinyint id. Very true — For example if you have 2,00,000 records and if your column size is varchar(20) and let’s say we have 8 bytes data for each row. So, they goes around 1.5 MB. Now, if we have lookup table and store ID as int, which consumes 4 bytes then your size will be half (0.76 MB). And obviously, if after entering 2,00,000 records. If someone comes and ask you that we need to change value of some “X” to “Y” then you no need to update 2,00,000 records. Just update one record and you are done!

Happy Lookup! 🙂

WCF Behavioral Contracts and Message Exchange Patterns

Challenge:

Architect was busy on other tasks, So, he was not able to share his WCF knowledge with you since last few days. He apologize for this!
Architect’s team liked his WCF Fundamentals notes and they requested him to share his all notes whatever he has related to WCF!
So, here’s the 3rd part (1st part, 2nd part) of WCF Story where our architect would like to share his WCF Behavioral Contracts and Message Exchange Patterns with you!

Solution:

Here’s the discussion between Architect and his team!
Contracts
Contract defines:

  • What service operations you are going to get?
  • How to format the messages you send to a given service.?
  • What will it do when it receives the messages?
  • What kind of response message you should expect in return, or if something goes wrong, what kind of fault does the service issue?

WCF Structures an overall contract by with its consumers by defining the following three core contracts:

  • Service Contract :- Defines which operations the service makes available to be invoked as request messages are sent to the service from the client.
  • Data Contract :- Defines the structure of the data included in the payloads of the messages flowing in and out of the service.
  • Message Contract :- Enables you to control the headers that appear in the messages and how the messages are structured.

Categorically there are two types of contracts:
1. Behavioral Contracts
2. Structural Contracts
Today we are going to delve in to first category — Behavioral contract
Behavioral Contracts

  • Tools to start defining WCF services.
  • It helps you to define how your service will behave (and in OOPs term we define class’s behavior using methods]

It focused on .NET attributes you need from System.ServiceModel namespace to specify the behavioral aspects of your WCF Service:

  • How the service behaves and what operations it exposes.
  • When the service might issue faults and what kind of faults it might issue.
  • What are the MEPs required to interact with the service? – Operation is request/response way, one way or duplex.

Basically there are 3 types of Behavioral contracts:

  1. ServiceContractAttribute
  2. OperationContractAttribute
  3. Fault Contracts

Let’s discuss them one by one.
ServiceContractAttribute
Service contract describes the operation that service provide. A Service can have more than one service contract but it should have at least one Service contract.

  • It describes the client-callable operations (functions) exposed by the service
  • It maps the interface and methods of your service to a platform-independent description
  • It describes message exchange patterns that the service can have with another party. Some service operations might be one-way; others might require a request-reply pattern
  • It is analogous to the element in WSDL

To create a service contract you define an interface with related methods representative of a collection of service operations, and then decorate the interface with the ServiceContract Attribute to indicate it is a service contract.
Named parameter options:

Named Parameter Description
Name
•Specifies a different for the contract instead of the default,
which is simply the interface or class type name. This contract name will
appear in WSDL.
Namespace
•Specifies a target namespace in the WSDL for the service.
The default namespace is http://tempuri.org . It’s really good practice to provide
Namespace.

Just a note : Please note that there are other named parameters as well. But it has been omitted intentionally to make things simple.
[sourcecode language=”csharp”]
[ServiceContract(Name="CalculatorService",
Namespace="http://schemas.demo.com/2011/10/calc/")]
public interface ICalculator
{
[OperationContract]
double Add(double number1, double number2);
}
[/sourcecode]
TIP:

  1. Always use Namespace property to provide a URI that in some way uniquely identifies both your organization and the conceptual or business domain in which the service operates. W3C standard – year and month to differentiate versions of your service.
  2. Good practice to use the Name property to remove the leading I because I is more of a .NET idiom.

OperationContractAttribute

  • Can be applied only to methods
    Used to declare the method belonging to a Service contract.

Named parameter options:

Named Parameter Description
Name
•Specifies a different name for the operation instead of using the default
which is the method name.
IsOneWay
•Indicates whether the operation is one-way and has no reply.

Just a note : Please note that there are other named parameters as well. But it has been omitted intentionally to make things simple.
[sourcecode language=”csharp”]
[ServiceContract(Name="CalculatorService",
Namespace="http://schemas.demo.com/2011/10/calc/")]
public interface ICalculator
{
[OperationContract(Name=“AddMethod",
IsOneWay=true)]]
double Add(double number1, double number2);
}
[/sourcecode]
Fault Contracts

  • When something goes wrong – what to do? (When service issues some faults then what type of information should be issued)
  • Faults (SOAP Faults) Vs. Exceptions (Exceptions) : Faults and exceptions are not the same thing. Exceptions, as referred to here, are a .NET mechanism used to communicate problems encountered as a program executes. The .NET Lang. allows you to throw, catch/handle, and possibly ignore exceptions so that they can be further propagated up the call stack. At the same point they should be handled else .NET runtime will terminate that thread.
    Fault, refer to the SOAP fault mechanism for transferring error or fault conditions from a service. The SOAP specification includes definition for SOAP Faults. Issue faults in a standard way.
  • WCF FaultException Class :- Provides standard mechanism for translating between two world of .NET Exceptions and SOAP Faults – WCF serialized your exception in SOAP Fault.
  • FaultContractAttribute :- enables a service developer to declare which faults a given service might issue if things go wrong. It can be applied to operations only and also more than once if needed.

[sourcecode language=”csharp”]
// Service Contract
[OperationContract]
[FaultContract(typeof(string))]
double Divide(double numerator, double denominator);
// Service Implementation
public double Divide(double numerator, double denominator)
{
if (denominator == 0.0d)
{
string faultDetail = "cannot divide by zero";
throw new FaultException(faultDetail);
}
return numerator / denominator;
}
[/sourcecode]
Message Exchange Patterns (MEP)
MEPs describe the protocol of message exchanges a consumer must engage in to converse properly with the service. For instance, if a consumer sends a message, it needs to know whether it should expect a message back or whether simply sending the request is enough. Further, can the consumer expect unsolicited messages back from the service? WCF supports
the following three MEPs:
1. One-way

  • One-way operation can be enabled by setting IsOneWay property to true in Operation contract attribute.
  • It can’t be used in conjunction with Fault Contract – Because it needs two-way channel.  Also, One way is not really one way!

In One-Way operation mode, client will send a request to the server and does not care whether it is success or failure of service execution. There is no return from the server-side, it is one-way communication.
Client will be blocked only for a moment till it dispatches its call to service. If any exception thrown by service will not reach the server.
Client can continue to execute its statement, after making one-way call to server. There is no need to wait, till server execute. Sometime when one-way calls reach the service, they may not be dispatched all at once but may instead be queued up on the service side to be dispatched one at a time, according to the service’s configured concurrency mode behavior. If the number of queued messages has exceeded the queue’s capacity, the client will be blocked even if it’s issued a one-way call. However, once the call is queued, the client will be unblocked and can continue executing, while the service processes the operation in the background.
[sourcecode language=”csharp”]
[ServiceContract(Name = "PizzaService",
Namespace = "http://schemas.demo.com/2011/10/pizza/")]
public interface IPizzaService
{
[OperationContract(IsOneWay = true)]
void CancelPizza(int pizzaOrderNumber);
}
[/sourcecode]
2. Request / Response [Default Message exchange pattern]

By default all WCF will be operated in the Request-Response [IsOneWay property of OperationContractAttribute is false) mode. It means that, when client make a request to the WCF service and client will wait to get response from service (till receiveTimeout). After getting the response it will start executing the rest of the statement. If service doesn’t respond to the service within receiveTimeout, client will receive TimeOutException
Void method doesn’t mean OneWay. It can use Request/Response and it’s really good practice to use it because this MEP allows to receive faults.
3. Duplex
Duplex MEP is a two-way message channel whose usage might be applicable in following situation:

  • Consumer sends a message to the service to initiate longer-running processing and then subsequently requires notification back from the service, confirming the requested processing has been done.

Duplex MEP has following issues:

  • it’s problematic in real world because a service needs connection back to the client – Firewalls and NAT problems.
  • Not Scalable. – We want stateless.
  • You lose interoperability. Because to implement Duplex MEP we need to use Callback method in WCF. But what if client is JAVA – which doesn’t supports callback methods.
  • Threading problems.

In Short Duplex is Complex! – Avoid using it. Use it if you really need it! – Okay, then how to deal with above given situation without Duplex?
Stay tuned for next story! (Just a note : If you would like to get email update whenever new story get posted, please do subscribe using subscription form — given right side)
Happy WCF Programming! 🙂

WCF Fundamentals and Quick start

Challenge:

After receiving lot of appreciation and positive comments on my first WCF article Why we need Windows Communication Foundation? and suggestion from Manaday (Which was going back of my mind. But somehow I was not bringing it in implementation), Henceforth I am going to post full WCF Series based on last fictional story.
So, here’s the 2nd part of WCF Story where our architect would like to share his WCF Fundamentals with you!

Solution:

Architect was kind enough to share his WCF Fundamental notes what he created for his team with you! [We should be thankful to him :)]
WCF provides API for creating systems that send messages between clients and services. Which can be sent either Intranet or Internet over TCP,HTTP,MSMQ, Web Services etc. Also it’s Interoperable!

Following are most of the concepts and terms used in WCF:

  • Message: Self-contained packets of data that may consist of several parts including header and body. All parts of a message can be encrypted and digitally signed except for the header which must be in clear text.
  • Service: A software module (EXE or DLL) that provides 1 to n endpoints with each endpoint providing 1 to n service operations.
  • Endpoint: A single interface that is used to establish communications between clients and hosts. Each endpoint has its own address that is appended to the base address of the service, making it a unique entity. A WCF service is a collection of endpoints.
  • Binding: A set of properties that define how an endpoint communicates with the outside world. At the very least, the binding defines the transport (HTTP or TCP) that is necessary to communicate with the endpoint. A binding may also specify other details such as security or the message pattern used by the endpoint.
  • System-provided bindings: A collection of bindings that are optimized for certain scenarios. For example, WSHttpBinding is designed for interoperability with Web Services that implement various WS-* specifications.
  • Service Contract: The contract defines the name of the service, its namespace, and other global attributes. In practice, a contract is defined by creating an interface (interface in C#) and applying the [ServiceContract] attribute. The actual service code is the class that implements this interface.
  • Operation Contract: Given that a service contract is defined by creating an interface and annotating it with [ServiceContract], an operation contract is a member method of that interface that defines the return type and parameters of an operation. Such an interface method must be annotated with [OperationContract].
  • Data Contract: Data types used by a service must be described in metadata to enable clients to interoperate with the service. The descriptions of the data types are known as data contracts and the types may be used in any message (parameters or return types).
  • Service operation: A method that is implemented and exposed by a service for consumption by any client. If a service contract is defined by creating an interface, then a service operation is the class that implements this interface.The method may or may not return a value, and may or may not take any arguments. Note while a method invocation might appear as a single operation on the client, it can result in sending multiple messages to the service. For example, a method with two arguments called on a WCF client results in two messages sent to the service.
  • Host: A host is an application (typically .exe) that is used to control the lifetime of a service. A host can be a console, a Windows Service, a Window Activation Service (WAS) and Internet Information Service (IIS) among others. For IIS, you can set a virtual directory that contains the service assemblies and configuration file. When a message is received, IIS starts the service and control its lifetime. When a client (or clients) end(s) the session, IIS closes the application and releases it resources.
  • Behavior: A behavior is a type (i.e., class) that augments the runtime functionality of a service. Service behaviors are enabled by applying a [ServiceBehavior] attribute to a service class and setting properties to enable various behaviors. Behaviors are used to control various runtime aspects of a service or endpoint. Behaviors are grouped according to scope: Common behaviors affect all endpoints, service behaviors affect only service-related aspects, and endpoint behaviors affect only endpoint-related properties. For example, an endpoint behavior may specify where and how to find a security credential.
  • Instancing: A service has an instancing model which controls how many instances of the service can run at one time. There are four instancing models: single, per call, per session, and shareable. The first two are similar in concepts to the Singleton and Single Call SAOs in .NET Remoting. Instancing is a behavior and and as such it is specified as part of the [ServiceBehavior] attribute as follows: [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)].
  • Client Application: A program that exchanges messages with one or more endpoints. The client application typically creates a WCF Client Object and then calling methods on this proxy object.
  • Channel: This is the transport connection between a client application and an endpoint in a service. A client uses a transport (TCP, HTTP, etc.) and an address to construct a channel to a specific endpoint.
  • WCF Client Object: This a client-side construct that encapsulates service operations as methods, in other words, a WCF Client Object is a proxy to the service methods. Note that any application can host a WCF Client Object, even an application hosting a service. Therefore, it is possible to create a service that includes and uses proxies to other services. These proxies are typically generated using the svcutil.exe command-line utility.
  • Metadata: data that is generated by the svcutil.exe command-line utility. This data includes:
  1. XML schema that define the data contract of the service.
  2. WSDL to describe the methods of the service.
  3. Application configuration files.
  • Metadata exchange point: An endpoint with its own address that is used to publish metadata.
  • Security: Security in WCF includes encryption of messages, integrity of messages, authentication and authorization. These functions can be provided by either using existing security mechanisms such as HTTPS or by implementing one or more of the various WS-* security specifications.
  • Message pattern: The message pattern determines the relationship and direction of messages between the client and the service. The most basic pattern is the one-shot (or one way) pattern is which a message is sent to the server but not response is expected. The most complex pattern is a dual HTTP pattern where two HTTP channels are constructed between a client and a service, with both sides invoking operations on each other.
  • Reliable messaging: The assurance that a message is received only once and in the order in which it was sent.
  • Sessions: A session is used to establish communication between a client and a service in which all messages are tagged with an ID that identifies the sessions. If a session is interrupted, it can be restarted with the session ID. If a service contract supports a session, then you will need to use Instancing to determine how the class that implements the service contract behaves during the session. See the Duplex Message Pattern example in Designing Contracts chapter.

Basic WCF Programming Lifecycle

Here are the basic steps of WCF Programming Lifecycle – Order matters!

  1. Define the service contract. A service contract specifies the signature of a service, the data it exchanges, and other contractually required data.
  2. Implement the contract. To implement a service contract, create the class that implements the contract and specify custom behaviors that the runtime should have.
  3. Configure the service by specifying endpoint information and other behavior information.
  4. Host the service in an application.
  5. Build a client application.

Just a note : Although the topics in this section follow this order, some scenarios do not start at the beginning. For example, if you want to build a client for a pre-existing service, you start at step 5. Or if you are building a service that others will use, you may skip step 5.

WCF Quick start

Following steps will help you to create your first WCF service (In this example we are going to create two console applications one console application will be hosting the service and second one will be consuming the service):
Step 1 : Define a Windows Communication Foundation Service Contract : When creating a basic WCF service, the first task is to create the contract for the service that is shared with the outside world that describes how to communicate with the service. This contract specifies the collection and structure of messages required to access the operations offered by the service. This is done by creating an interface that defines the input and output types, which apply the ServiceContractAttribute to the interface and OperationContractAttribute to the methods that you want to expose.

NOTE : We need to add reference to System.ServiceModel

The service contract that is used here employees a request-reply message exchange pattern by default that is not explicitly specified. You can specify this and other message exchange patterns for client-service communications by setting properties of the OperationContractAttribute and ServiceContractAttribute in the contract.
Example:
[sourcecode language=”csharp”]
namespace WCFService
{
[ServiceContract]
public interface ICalculator
{
// It will be exposed to clients
[OperationContract]
double Add(double number1, double number2);
}
}
[/sourcecode]
Step 2 : Implement a Windows Communication Foundation Service Contract : Implement the Service Contract defined in step1.
Example:
[sourcecode language=”csharp”]
namespace WCFService
{
public class CalculatorService : ICalculator
{
#region ICalculator Members
public double Add(double number1, double number2)
{
Console.WriteLine("Service called at : {0}", DateTime.Now.ToString());
Console.WriteLine(@"Calculator Service got called
with two parameters {0} and {1}",
number1,
number2);
double result = number1 + number2;
Console.WriteLine("The result is : {0}",result);
Console.WriteLine("——————————-");
return result;
}
#endregion
}
}
[/sourcecode]
Step 3 : Run a Basic Windows Communication Foundation Service :
This topic describes how to run a basic Windows Communication Foundation (WCF) service. This procedure consists of the following steps:

  • Create a base address for the service.
  •  Create a service host for the service.
  •  Enable metadata exchange.
  •  Open the service host.

Example:
[sourcecode language=”csharp”]
namespace WCFService
{
class Program
{
static void Main(string[] args)
{
// Address
Uri baseAddress =
new Uri("http://localhost:8080/WCFService/Service");
// Host
ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService),
baseAddress);
try
{
// Binding, Contract
serviceHost.AddServiceEndpoint(typeof(ICalculator),
new WSHttpBinding(),
"CalculatorService");
// Metadatabehavior
// WSDL information we need to expose to clients
// it works on HTTP GET Method
ServiceMetadataBehavior serviceMetadatabehavior
= new ServiceMetadataBehavior();
serviceMetadatabehavior.HttpGetEnabled = true;
serviceHost.Description.Behaviors.Add(serviceMetadatabehavior);
// Start the service
serviceHost.Open();
Console.WriteLine("Service started : {0}",
DateTime.Now.ToString());
// Stop the service
Console.WriteLine("Press ENTER to shut down the service");
Console.ReadLine();
serviceHost.Close();
Console.WriteLine(@"Service shutdown successfully.
Thank you for using our service!");
}
catch (CommunicationException ce)
{
Console.WriteLine(ce.Message);
serviceHost.Abort();
}
}
}
}
[/sourcecode]
Step 4: Create a Windows Communication Foundation Client : This topic describes how to retrieve metadata from a WCF service and use it to create a proxy that can access the service. This task is most easily completed by using the ServiceModel Metadata Utility Tool (Svcutil.exe) provided by WCF. This tool obtains the metadata from the service and generates a managed source code file for a client proxy in the language you have chosen. In addition to creating the client proxy, the tool also creates the configuration file for the client that enables the client application to connect to the service at one of its endpoints.

svcutil.exe /language:cs /out:generatedProxy.cs /config:app.config

By default, the client proxy code is generated in a file named after the service (in this case, for example, CalculatorService.cs or CalculatorService.vb where the extension is appropriate to the programming language: .vb for Visual Basic or .cs for C#). The /out switch used changes the name of the client proxy file to “generatedProxy.cs”. The /config switch used changes the name of the client configuration file from the default “output.config” to “app.config”.

Just a note : If you would like to test your service quickly. You can use WCFTestClient.exe utility which will help you to test your service without writing a single line of code for your WCF Client!


Step 5: Configure a Basic Windows Communication Foundation Client : This topic adds the client configuration file that was generated using the Service Model Metadata Utility (Svcutil.exe) to the client project and explicates the contents of the client configuration elements. Configuring the client consists of specifying the endpoint that the client uses to access the service. An endpoint has an address, a binding and a contract, and each of these must be specified in the process of configuring the client.
svcutil.exe will provide you the default configuration automatically.
Step 6 : Use a Windows Communication Foundation Client : Once a Windows Communication Foundation (WCF) proxy has been created and configured, a client instance can be created and the client application can be compiled and used to communicate with the WCF service. This topic describes procedures for creating and using a WCF client. This procedure does three things: creates a WCF client, calls the service operations from the generated proxy, and closes the client once the operation call is completed.
Now, copy paste the svcutil generated files (CS and Config file) within your console project and then you can call your service from your client application as shown below:
Example:
[sourcecode language=”csharp”]
namespace WCFClient
{
class Program
{
static void Main(string[] args)
{
CalculatorClient calculatorClient = new CalculatorClient();
Console.WriteLine("Proxy calling service…");
Console.WriteLine(calculatorClient.Add(10, 20));
// Good practice
calculatorClient.Close();
Console.WriteLine("closed!");
}
}
}
[/sourcecode]
And then first start your service (your service must be in running state before you run the client) and then run the client. And this is how it will look like:

Resources

Mike Taulty’s Video : Windows Communication Foundation:” Hello World”:
http://go.microsoft.com/?linkid=4091084
http://download.microsoft.com/download/f/b/3/fb3c2a8b-604e-479b-ab22-e31dc094a40d/WCF_Hello_World.zip
Stay tuned for next story! (Just a note : If you would like to get email update whenever new story get posted, please do subscribe using subscription form — given right side) 🙂
Happy WCF Programming! 🙂

Why we need Windows Communication Foundation?

Challenge:

In earlier days, when i was totally newbie to WCF, I was not clear why we need WCF? one thing I was clear that it has something to do with Web Services. But other than that nothing was much clear.
Then at one fine day, I came across Shivprasad Koirala’s .NET Interview questions book. In which he explained why we need WCF and what is WCF using a fictional story. It is really nicely written and it clears why we need WCF.
Before couple of days, I got good time (as I was on holidays) to convert that story in a comic — To make it more funny (And that’s what philosophy I follow — “Coding should be fun” :-)) and comic blog — a new concept which I always wanted to start!
So, here we go my first comic blog article which explains why we need WCF?

Solution:

  • Long Long time ago there lived a hardworking and a nice architecture.
  • Develop a Booking Engine which books tickets for any flight carriers.
  • The nice and hardworking architecture and his team developed a nice booking engine by which you can book tickets through any of the flight Carriers. The Travel Agent Company was very happy with the architecture and his team Member’s achievements.

  • As time passed by the travel agent’s business grew in multiples
  • Architecture and his team was very excited and they started to work on this new stuff
  • All franchises run on Windows Platform.
  • Booking engine was located in the main head office and all the franchise should communicate to this booking engine.
  • After months he rolled out his project successfully.

  • Time passed by and because of the good automated booking service more companies wanted to take the franchise from the travel agent. But the big issue was many of the franchise did not have windows operating system. They worked on Linux and other Non-Microsoft operating systems.
  • Due to this limitation travel agent was losing lot of franchise business.
  • Now, booking engine runs on two platforms .NET Remoting (for Windows based clients) and Web Services (for non-windows based clients).

  • Franchise client had to wait to get response and was not able to process the next ticket booking until the first one was served. Travel Agent started receiving huge complaints because of this synchronous processing.
  • Booking engine had the capacity of serving 20 tickets / second but it had now to serve 50 tickets / second.
  • when the travel agent makes a booking it will come and fall in the queue and release the travel agent. Booking engine will always poll for this queue. When the booking engine finishes he will publish the booking results back to the queue. Travel agent client can then come at his leisure and see the results.

  • Everyone in the travel company was really happy and impressed by the architect and his team members
  • Travel Agent then felt a huge necessity of a good security model with the booking engine.

  • Till now the travel agent was booking one ticket at a time. But soon he started getting lot of orders to book group family tickets.
  • Consistency – If father’s ticket gets canceled. Kid’s ticket should also be got canceled.


They were working on:

  • .NET
  • .NET Remoting
  • Web Services
  • MSMQ
  • WSE
  • COM+


WCF is a unification of all distributed technologies like:

  • .NET Remoting
  • MSMQ
  • Web Services
  • COM+

Thanks a lot Shivprasad Koirala for writing such a nice story!
Happy Coding! 🙂